I am currently writing a little applet to modify files in a certain way. However, I am noticing wildly strange behaviour. I have an output file that is fopen'd in "a+" mode. If the file did not exist and was created, the resulting output is total garbage (however, it exhibits the expected filesize). If the file already existed, the whole program crashes on the matching call to fclose for the same file. I am using plain old standard fprintf calls to output to the file.

Can anyone help me figure out what is causing this?

Recommended Answers

Can you show your code?

Jump to Post

All 2 Replies

Can you show your code?

What operating system/version are you using. According to the Linux man page for fopen, the usage of "a+" is this:

       a+     Open for reading and appending (writing at end of file).  The file is created if it does not exist.  The initial  file position for reading is at the beginning of the file, but output is always appended to the end of the file.

In any case, I have NEVER seen a crash on any Linux or Unix system using this. Windows? Don't know about Win7, but I never had any problems on XP and earlier versions of Windows NT.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.