那我运行这段程序的时候,它并没有生成新的文件,我也不太明白是怎么回事。我用的是xcode [quote=引用 10 楼 KenZhang1031 的回复:] 我没刻意放哪,文件原来没有的,fopen("table.txt","w")会生成新文件。 [quote=引用 9 楼 u013190286 的回复:] 最后再问下,你的text文件是跟.c文件放在一起的,是这样吧?谢谢了 [quote=引用 8 楼 KenZhang1031 的回复:] 可能你在fprintf之后看的,文件可能还在缓冲区里,没更新到文件里,你在fclose之后再看。 [quote=引用 6 楼 u013190286 的回复:] [quote=引用 3 楼 KenZhang1031 的回复:] 你怎么知道文件没打开?应该这么写吧? if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
我没刻意放哪,文件原来没有的,fopen("table.txt","w")会生成新文件。 [quote=引用 9 楼 u013190286 的回复:] 最后再问下,你的text文件是跟.c文件放在一起的,是这样吧?谢谢了 [quote=引用 8 楼 KenZhang1031 的回复:] 可能你在fprintf之后看的,文件可能还在缓冲区里,没更新到文件里,你在fclose之后再看。 [quote=引用 6 楼 u013190286 的回复:] [quote=引用 3 楼 KenZhang1031 的回复:] 你怎么知道文件没打开?应该这么写吧? if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
最后再问下,你的text文件是跟.c文件放在一起的,是这样吧?谢谢了 [quote=引用 8 楼 KenZhang1031 的回复:] 可能你在fprintf之后看的,文件可能还在缓冲区里,没更新到文件里,你在fclose之后再看。 [quote=引用 6 楼 u013190286 的回复:] [quote=引用 3 楼 KenZhang1031 的回复:] 你怎么知道文件没打开?应该这么写吧? if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
可能你在fprintf之后看的,文件可能还在缓冲区里,没更新到文件里,你在fclose之后再看。 [quote=引用 6 楼 u013190286 的回复:] [quote=引用 3 楼 KenZhang1031 的回复:] 你怎么知道文件没打开?应该这么写吧? if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
[quote=引用 3 楼 KenZhang1031 的回复:] 你怎么知道文件没打开?应该这么写吧? if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
你怎么知道文件没打开?应该这么写吧? if((fic=fopen("table.txt","w")) != NULL) { printf("file opened\n"); // 文件打开 } else { printf("file open error\n"); // 文件打开错误 }
69,369
社区成员
243,082
社区内容
加载中
试试用AI创作助手写篇文章吧