Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!rpi!sci.ccny.cuny.edu!phri!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: It's unexplainable... Message-ID: <15029@smoke.brl.mil> Date: 31 Jan 91 18:43:53 GMT References: <1991Jan30.203605.14481@bronze.ucs.indiana.edu> <8412@mgweed.UUCP> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 22 In article <8412@mgweed.UUCP> prg@mgweed.UUCP (Gunsul) writes: >In article <1991Jan30.203605.14481@bronze.ucs.indiana.edu>, speelmo@bronze.ucs.indiana.edu (Lance Speelmon - UCS) writes: >| #include >| 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.