开发者

Garbage characters in file [duplicate]

开发者 https://www.devze.com 2023-03-22 12:52 出处:网络
This question already has answers here: What is character encoding and why should I bother with it (4 answers)
This question already has answers here: What is character encoding and why should I bother with it (4 answers) Closed 5 years ago.

I am appending a string to a file after each 1 sec. I have recently foun开发者_JAVA百科d that the data rather one character is sometimes garbage or replaced. For example:

"This is a String" appears as "This is a Str&ng" or "This i%s a String"

So, my question here is that, does this correspond to file system corruption or what. Because if there would have any mistake in my code then I should have seen a long string of garbage value at the end or so. But that is not the case. I only see one character garbage value.

It follows the standard file write operation:

fHandle = fopen("A:\", "a");

strcpy(Buff, "This is a String");

fwrite(Buff, strlen(Buff), 1, fHandle); 


With only 3 lines of code in the question I can only suggest you check the file encoding and/or casts in your string arrays.

0

精彩评论

暂无评论...
验证码 换一张
取 消