I suppose this should make things clear...
I haven't got a linux machine to check it . But I think that this is the way you do it.
Code:
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc,char **argv)
{
int num,i;
struct dirent **name_list;
struct stat BUFFER;
//The path of the directory to be listed should be given as cmd line argument
num=scandir(argv[1],&name_list,0,alphasort);
for(i=0;i<num;i++)
{
stat(name_list[i]->d_name,&BUFFER);
//To check if it is a dir or not
if(S_ISDIR(BUFFER.st_mode))
{
printf("%s --- directory \n",name_list[i]->d_name);
}
}
}
P.S :- Is your program working fiine ??? I think there is an error with the getcwd thing...Maybe I am wrong about your program