【发布时间】:2016-05-25 23:22:00
【问题描述】:
我一直在尝试使用 c 中的以下代码打开目录的内容。
#include<stdio.h>
#include<dirent.h>
main(int *argc,char *argv[]){
DIR *d;
struct dirent *dir;
d=opendir(*argv);
if(d){
while((dir = readdir(d))!= NULL){
printf("%s\n",dir->d_name);
}
closedir(d);
}
}
然后我执行如下命令:
gcc test.c ~/Desktop
但它返回如下内容:
/usr/bin/ld: cannot find /home/cse-swlab5/Desktop: File format not recognized collect2: ld returned 1 exit status
我没有找到原因。我也试过放
d=opendir("<path of the file here>");
在这种情况下程序可以工作。我在传递参数时做错了什么吗?请帮忙。
【问题讨论】: