当我运行我的应用程序,如./a.out我有这个错误: 我编译我的应用程序,如:gcc test1.c。 内存故障我的简单程序中的内存错误C
我的代码是
int main (void)
{
DIR *dp;
struct dirent *ep;
const char *path_dir ="/home/risorse/ae23054/Giuseppe";//Inserire la directory qui
dp = opendir (path_dir);
if (dp != NULL)
{
while (ep = readdir (dp)){
printf(ep->d_name);
char nome_file[256];
strcpy(nome_file,ep->d_name);
FILE *fd=fopen(nome_file, "a+");
fprintf(fd,"\nEXIT");
fclose(fd);
}
(void) closedir (dp);
}
else
perror ("Non posso aprire la directory");
return -1;
}
感谢
你做任何调试 –
检查'fopen'的返回值。 – sujin
你没有初始化'ep'结构? –