我试着去学C,我使用tutorialspoint,他们给了我不会在我的电脑上做任何事情的函数,该函数是:着写文本文件
#include <stdio.h>
int main(){
FILE *fp;
fp = fopen("/tmp/test.txt", "w+");
fprintf(fp, "This is testing for fprintf...\n");
fputs("This is testing for fputs...\n", fp);
fclose(fp);
}
我错过什么?
你有写入权限“/ tmp”吗? – jdarthenay
尝试写入其他文件夹。 (这可能是后台程序删除使用的文件的工作。) – BLUEPIXY
检查'fopen()'的结果。如果它不能创建文件,它会返回NULL。 – jdarthenay