Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习C,我有一个问题。我正在尝试将字符串附加到文件中。但是,每次附加一个字符串时,它都必须在下一行(有点像 println 而不是 print)。
我无法将函数追加到下一行。相反,它只是不断地追加在同一行。我该怎么做呢?
void FileWriter(char *cmmd) { FILE *fp; fp = fopen("xxx.txt", "a"); fprintf(fp, "%s", cmmd); fclose(fp); }
谢谢!
说这个:
fprintf(fp, "%s\n", cmmd); // ^^
对不起,我很笨。我在 %s 之后放了一个 \n 并且它起作用了。也许有更好的方法?