当我使用此代码时
FILE *f = fopen(file, "wb");
fflush(f);
if (f==NULL) {
//perror(f);
return 0;
}
else{
fwrite(text, sizeof(char), strlen(text), f);
int i = fprintf(f, "%s", text);
if (i>0) {
fclose(f);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
如果我写的话,(text是const char text[1024000],它被设置为函数中的一个参数)
This is a test
This is a test
Run Code Online (Sandbox Code Playgroud)
为了测试它是否可以写多行,它会写出来
This is a test
This is a testThis is a test
This is a test
Run Code Online (Sandbox Code Playgroud)
为什么我会得到这种奇怪的行为?
你写了两次:
fwrite(text, sizeof(char), strlen(text), f);
int i = fprintf(f, "%s", text);
Run Code Online (Sandbox Code Playgroud)
选一个