晚上好人。我正在尝试将字符串打印到结果文件中,但事情并不顺利。 例如,我的数据文件的内容是:
Hello, today
is a
Good Day
What is going
On here?
结果文件结果显示:
On here?
g
这是我的打印功能:
void print(char B[])
{
printf("%s", B); //NOTE; this string represents a line of data file and works!
FILE *wfile;
if ((wfile = fopen("result.txt","w")) == NULL){
printf("File did not open!!!/n");
exit(1);
}
fprintf(wfile, "%s", B);
}
我不知所措,非常感谢任何形式的投入。
答案 0 :(得分:1)
感谢评论者,我意识到这不是
if ((wfile = fopen("result.txt","w")) == NULL)
我不得不改变" w"到" a"因为我想将字符串附加到文件
if ((wfile = fopen("result.txt","a")) == NULL)