Click to See Complete Forum and Search --> : fprintf...


BeePo
August 20th, 2002, 09:39 AM
hi i have a function called

writetofile(const char* filename)
{
FILE *stream;
stream = fopen(filename,"a+");
fprintf( stream,"%s",strptr); // printing the orginal string
fprintf(stream," ");
fclose(stream);
}


when I call the function first time, i got no proglem.. but when i calll next time, I got run time error.... why is that?

willchop
August 20th, 2002, 11:44 AM
BeePo,

Where is the error occurring? Can you pin-point the line
of code in your debugger? I would pay special attention
to the fopen return file pointer and the "strptr" pointer.
Make sure niether are null and the "strptr" is properly
null terminated and not already deallocated. You could
also save yourself a line of code by combining the two
fprintf statements into one. Just put the space of the
string conversion specifier.

Regards, willchop