c - writing values in a text file, getting run time check error -


I am programming in Windows 7, using MS Visual C ++ 2010.

I have an API that gives me access to such error codes:

Pre>

I need to write this code, a text file, here's how I proceeded:

  four buffers [10]; Strcpy (Buff, lResult.GetCodeString ()); PFile_display = fopen ("D: \\ ABCD \\ myfile_display.txt", "a +"); Fputs ("\ n back error is vlaue", pFile_display); Fillit (fond, size (four), size (fond), pfile_display);  

Is there a better way to do this, because I'm getting a runtime check error and I suspect that I'm doing something wrong here.

Yes, this is a different way of doing this.

  1. You do not know how long an error message is, but you are reserved cell for only 10 characters. This is not much.
  2. There is no need to copy the message in another buffer before typing in the file.
  3. Use sizeof to calculate the length of the string is broken.
  4. There is no need to use a lower-level function to write binary data (i.e., fwrite () ), when your data is string

Just do:

  fprintf (pFile_display, "error '% s' \ n", lResult.GetCodeString ());  

By the way, it is found that the return value of GetCodeString () is probably not a string. You should:

  fprintf (pFile_display, "error '% s' \ n", lResult.GetCodeString (). GetAscii ()); To get the proper format  

Surely you should get compiler warnings for this.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -