-3

I am appending a string to a file after each 1 sec. I have recently found 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); 
jscode
  • 121
  • 1
  • 1
  • 6
  • Is that your actual code or something you just wrote here? Please provide us with your actual code. Ideally something we can compile and run ourselves, but shows the exact same behavior as you're seeing. – Bart Jul 22 '11 at 17:52
  • 2
    This is not what your code looks like, it could never work. Posting just random lines of code isn't useful. – Hans Passant Jul 22 '11 at 17:52
  • 1
    I'm suprised any observable results occur when you write to A:\ - did it let you open the root directory as a file? I can't blame it for haveing unexpected results in that case! – FastAl Jul 22 '11 at 18:00
  • @FastAI As it stands that line won't even compile. So it can't be the OP's actual code. – Bart Jul 22 '11 at 18:04

1 Answers1

3

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.

matfillion
  • 867
  • 6
  • 10
  • 2
    +1 For apparently correctly answering a question without a lot of relevant info to go on. I take my hat off to you.... ;) – Bart Jul 22 '11 at 18:07