Path: utzoo!attcan!uunet!decwrl!ogicse!oregon!jmeissen From: jmeissen@oregon.oacis.org ( Staff OACIS) Newsgroups: comp.sys.amiga Subject: Re: program question, stdin, stdout. Message-ID: <573@oregon.oacis.org> Date: 30 Jul 90 17:24:19 GMT References: <2033@bnlux0.bnl.gov> Organization: Oregon Advanced Computing Institute (OACIS), Beaverton, OR Lines: 18 In article <2033@bnlux0.bnl.gov> kushmer@bnlux0.bnl.gov (christopher kushmerick) writes: > while ((c=getchar())!=EOF) putchar(c); >When I replace putchar with printf("%d\n",c) the program works as I woud >expect, it prints out the ascii value of the character I hit. >Any ideas why the above prog should not work? Yes, the problem is that by default stdout is buffered. When you call putchar() (a macro, I think) it merely puts characters into a buffer until the buffer fills up, then it gets flushed. printf() gets around this problem by calling fflush() each time it gets called. You can either set stdout to unbuffered by calling setnbf(), or call fflush() after each putchar() call. -- John Meissen .............................. Oregon Advanced Computing Institute jmeissen@oacis.org (Internet) | "That's the remarkable thing about life; ..!sequent!oacis!jmeissen (UUCP) | things are never so bad that they can't jmeissen (BIX) | get worse." - Calvin & Hobbes