I thought I would check errno after a long string of printf calls ...
I thought I'd check errno after a long string of printf calls, to see if any of them had failed:
errno = 0;
if(errno != 0)
fprintf(stderr, "printf failed: %s\n", strerror(errno));
Why is it printing something strange like ``printf failed: Not a typewriter'' when I redirect the output to a file?
Many implementations of the stdio package adjust their behavior slightly if stdout is a terminal. To make the determination, these implementations perform some operation which happens to fail (with ENOTTY) if stdout is not a terminal. Although the output operation goes on to complete successfully, errno still contains ENOTTY. This behavior can be mildly confusing, but it is not strictly incorrect, because it is only meaningful for a program to inspect the contents of errno after an error has been reported. (More precisely, errno is only meaningful after a library function that sets errno on error has returned an error code.)
In general, it's best to detect errors by checking a function's return value. To check for any accumulated error after a long string of stdio calls, you can use ferror.
2015-10-14, 977👍, 0💬
What does static variable mean? There are 3 main uses for static variables: If you declare within a ...
What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void...
Can one change the mouse pointer in Forms? The SET_APPLICATION_PROPERTY build-in in Oracle Forms all...
Can each Java object keep track of all the threads that want to exclusively access to it?
If XML does not have closing tag will it work? No, every tag in XML which is opened should have a cl...