【发布时间】:2014-10-31 06:02:02
【问题描述】:
对 C 和 Unix 相当陌生。
我目前有:
#include "stdio.h"
#include <dirent.h>
#include <unistd.h>
int main(int argc, char ** argv)
{ char * current = get_current_dir_name(); //where error occurs
DIR * directory = NULL;
directory = opendir(current);
if(directory == NULL)
return -1;
struct dirent * ent;
while((ent = readdir (directory)) != NULL)
printf("%s\n", ent -> d_name);
if(closedir(directory) < 0)
return -1;
}
有人告诉我:dir.c:15: 警告:初始化使指针从整数而不进行强制转换
显然做了一些非常愚蠢的事情,并且需要一些帮助。
【问题讨论】:
-
get_current_dir_name()声明在哪里?你的警告告诉你问题 - C 认为get_current_dir_name()正在返回一个int(没有人告诉它的默认类型) -
为什么
stdio在" "里面