【发布时间】:2013-01-09 13:23:13
【问题描述】:
好的,所以我有一个客户结构,我正在尝试将客户的每个属性写入文本文件的单独行中。这是代码
custFile = fopen ("customers.txt", "w+");
fprintf(custFile, "%s", cust[cust_index].name);
fprintf(custFile, "\n");
fprintf(custFile, "%s", cust[cust_index].sname);
fprintf(custFile, "%s", cust[cust_index].id);
fclose(custFile);
数据是文本文件的形式,一行输出
数据很好,只是打印在一行中。当我给我的朋友我的代码时,它可以正常工作。
P.s 我不知道这是否有什么不同,但我是在 mac 上编程
【问题讨论】:
-
不要刷新标准输入,这是未定义的行为。
-
可以从stackoverflow.com/questions/1402673/…中已经给出的答案中推断出有关此行为的解释
-
\r不是 Mac 上的换行符吗?