/\/\/\/\/\/\/\如何char*形式返回文件名/\/\/\/\/\/\/\/\/\
假如我有一个文件夹,里面有文件,yxiang1.txt
student.txt
abaccc.txt
'
'
'
怎么样让这些文件的文件名在屏幕上显示
[ 本帖最后由 yxiangyxiang 于 2012-2-7 23:21 编辑 ]
程序代码:#include <stdio.h>
#include <dirent.h>
int main()
{
struct dirent *dp = NULL; // 用来读目录项(DIRectory ENTry)的指针。
DIR *dir = opendir("."); // 打开当前目录(".")
// if dir == NULL, ... // 多少要想照顾照顾有错误的情况,那还得加点代码。
while ((dp = readdir(dir)) != NULL) {
printf("%s\n", dp->d_name); // 循环把文件名打出来就行了。
}
return 0;
}