Does the ferror
in this example check check both fprintf
s for error, or just the second one?
FILE * myout;
if ((myout = fopen("Assignment 11.txt", "a")) != NULL)
{
fprintf(myout, "First print ", str1);
fprintf(myout, "Second print", str1);
if (ferror(myout))
fprintf(stderr, "Error printing to file!");
fclose(myout);
}
If an error occurs, it won't be reset unless
clearerr
is called on your stream, so yes, an error occuring on any of both writes is recorded.from ferror manual page:
But you could also simply use
fprintf
return code to see if something went wrong:(fprintf manual page)
Like this (Thanks Jonathan for pointing out the errors in the original post):