System Resources?

I am running a C program on a SCO box. There are multiple users on using the system resources. My problem is when using fprintfs in the program. I am writing to a log every thing I read in from a file after doing some formatting. I write out to the log with the fprintfs in groupings like 10 fprintfs in a row and then further on down in the program 75 more fprintfs all in a row. When it writes the 75 fprinfts it looses the valid data about midway through the writes to the log. I noticed when I comment out the 1st grouping of 10 fprintfs the second group of 75 fprintfs still lose valid data during the writes, but not till further down in sequence. Although it is not a direct 1 to 1 relationship the more fprintfs I comment out in the beginning of the sequence the further it gets to end of the fprinfts to the point that it will finish writing to the log all the valid data.

Could limited memory resources cause this problem by reallocating memory, if the available memory is less then when the program was compiled, or would it error out during execution?

You need to use fflush(stderr) after every fprintf you use, this way all the data' s will get printed correctly, just try out, if you still face any problems reply with more details.

Cheers :slight_smile:

From the fflush man page:

fflush() causes any unwritten data for that stream to be written to the file, and the st_ctime and st_mtime fields of the underlying file are marked for update.

In the past, I've typically masked each fflush by using a local subroutine that takes the same input as fprintf, but also does the flush - keeps the code readable if fprintf(s) abound.

Cheers,

Keith

I just do a setvbuf(stdout, NULL, _IONBF, 0) if I don't want buffering.

But I'm not sure that buffering per se is the issue here. The "lose valid data" does not strike me as the way to describe a delay in seeing the data. It may be that the OP has a bug that resulted in re-using the area already assigned as a buffer. When the buffer fills, the other data is trashed. If this is the case, turning off buffering may hide the symptom, but it does not fix the root problem.