有些难以理解的程序(如下)。
我有一点疑惑于语句
现在问题是:如何在所需位置插入
任何帮助都将不胜感激。
fputs("\n",fp)
。
例如,让我输入:
如果我不提及It doesn't matter what you are underneath
Its what you do that defines you.
fputs("\n",fp)
,字符串就会显示在单行上。但使用此代码后,字符串就会保存为原样。现在问题是:如何在所需位置插入
\n
,因为通常情况下 \n
应该添加在文本末尾。任何帮助都将不胜感激。
int main()
{
FILE *fp;
char s[80];
fp=fopen("abc.txt","w");
if(fp==NULL)
{
puts("Cannot open file");
exit(1);
}
printf("\nEnter a few lines of text:\n");
while(strlen(gets(s))>0)
{
fputs(s,fp);
fputs("\n",fp);
}
fclose(fp);
return 0;
}
Type "char" is not compatible with parameter type "const char*"
,请确保你使用了双引号"\n"
。 - CodeManX