#include <stdio.h>
int main()
{
FILE* f = fopen("D:/document/test.txt", "w+");
char s[] = { "12345" };
if (f == NULL)
{
printf("open error!\n");
return 0;
}
fprintf(f, "%s", s);
fclose(f);
return 0;
}
修改如下,供参考:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s[] = { "12345" };
FILE* f1 = fopen("D:\\f1.txt", "w+");
if (f1 == NULL){
printf("Fail to open file!\n");
//exit(0);
}
else{
fprintf(f1, "%s", s);
fclose(f1);
}
return 0;
}
如果路径里写/,那么只应该写一个
如果你写\,那么就要写2个
/不是转义符呀
你写//那代表路径中间有个文件夹名字是空