It's unexplainable...

Doug Gwyn gwyn at smoke.brl.mil
Fri Feb 1 05:43:53 AEST 1991


In article <8412 at mgweed.UUCP> prg at mgweed.UUCP (Gunsul) writes:
>In article <1991Jan30.203605.14481 at bronze.ucs.indiana.edu>, speelmo at bronze.ucs.indiana.edu (Lance Speelmon - UCS) writes:
>| #include <stdio.h>
>| void main(void){
>|   printf("The date is: ");
>|   system("date");
>|   printf("\n");
>| }
>Lance, just before your printf statement, insert this line:
>	setbuf(stdout, 0);
>I think you'll be pleased with the results..  You might want to RTFM on
>setbuf after you see the results.  Many people have been had by this one!

This is not a very good solution, since it forces stdout to be unbuffered.
(By the way, the only reason you can write 0 instead of an explicitly
correct null pointer type is that there is presumably a prototype in scope.
On non-ANSI C implementations, you should use (char*)0 or (char*)NULL for
the second argument.)  A better solution is to include fflush(stdout); just
before invoking system().

Note also that main() is misdefined.  A function returning int is expected
by the run-time system.



More information about the Comp.lang.c mailing list