コマンドライン入力を介してパスを受け入れています。
私がする時
dir=opendir(args[1]);
ループに入りません...つまりdir==null
..。
コマンドライン入力をdirポインタに渡すにはどうすればよいですか?
void main(int c,char **args)
{
DIR *dir;
struct dirent *dent;
char buffer[50];
strcpy(buffer, args[1]);
dir = opendir(buffer); //this part
if(dir!=NULL)
{
while((dent=readdir(dir))!=NULL)
printf(dent->d_name);
}
close(dir);
}
./a.out /root/TEST is used to run the program..
./a.out --> to execute the program
/root/TEST --> input by the user i.e valid path