【发布时间】:2012-12-29 14:05:42
【问题描述】:
我有一个奇怪的问题:
我将一个文件读入一个 buf 并尝试在 ssh (Linux) 中运行它..
我的文件包含:
We
I
a
所以这是我的 buf:
现在我创建一个新文件并将 buf 粘贴到这个新文件中:
FILE*nem_file_name;
nem_file_name= fopen("email1.clear","wb"); //create the file if not exist.
fwrite (buf, sizeof(char), strlen(buf),nem_file_name); //write the new sensored mail to the file.
在这种情况下,文件:email1.clear 已创建,但它包含以下内容:
We Ia
当我将它复制到剪贴板并粘贴到这个主题时,它被粘贴了:
We
I
a
为什么我的文件中没有“结束行”?我希望它像我在剪贴板中的一样:/
更新 我尝试通过以下方式手动创建 buf:
char buf[10];
buf[0] = 'W';
buf[1] = 'e';
buf[2] = 32;
buf[3] = 13;
buf[4] = 10;
buf[5] = 'I';
buf[6] = 13;
buf[7] = 10;
buf[8] = 'a';
buf[9] = 0;
(注意我没有将文件读入buf,而是手动进行的)
然后:
FILE*nem_file_name;
nem_file_name= fopen("email1.clear","wb"); //create the file if not exist.
fwrite (buf, sizeof(char), strlen(buf),nem_file_name);
并且文件email1.clear 是按照我的意愿创建的:
We
I
a
看不懂!
【问题讨论】:
-
您使用什么程序查看文件?你检查过里面的编码了吗?
-
在十六进制编辑器中查看结果文件。
-
'a' 后没有新行 (CR-LF),“标准”文本文件以新行结尾。
-
编码可以在记事本中给出strange results,即它并不总是显示您希望它显示的内容
-
请看我对这个主题的更新:/