Geschrieben von: / Posted by: Uri Blass at 01 March 2004 21:03:45:
I decided to use the PrintLog function and I have a question about using it
Today I print the hash size both on the screen and on the logfile by
logmovei=fopen(logstring, "a+t");
fseek(logmovei,0,SEEK_END);
fprintf(logmovei,"hash in mbytes=%d\n",hash_in_mbytes);
fclose(logmovei);
printf(" hash size in mbytes ");
printf(" %d ",hash_in_mbytes);
The question is what exactly I should delete from that code
It is clear to me that I should add
PrintLog("hash in mbytes=%d\n",hash_in_mbytes);
I see that I can do my code slightly smaller by deleting
fprintf(logmovei,"hash in mbytes=%d\n",hash_in_mbytes);
printf(" hash size in mbytes ");
printf(" %d ",hash_in_mbytes);
There is a difference when it print new line on the screen but the difference is not important
I guess that I can delete also the fseek command.
The point is that I believe that having always fopen fclose is not efficient programming.
I thought that it may be better to have one fopen and one fclose when I go out of the program but I do not want the program to forget to close files because of a bug so I think that fopen and fclose should be in the original PrintLog function and I wonder if there is a reason that it is not there.
Here is again the PrintLog function.
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri