Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!elroy!ucla-cs!heather From: heather@maui.cs.ucla.edu (Heather Burris) Newsgroups: comp.lang.c Subject: Re: Strange C Problem Keywords: Linked Lists Message-ID: <23802@shemp.CS.UCLA.EDU> Date: 10 May 89 14:09:33 GMT References: <13812@paris.ics.uci.edu> Sender: news@CS.UCLA.EDU Reply-To: heather@cs.ucla.edu (Heather Burris) Distribution: na Organization: UCLA Computer Science Department Lines: 36 In article <13812@paris.ics.uci.edu> bvickers@bonnie.ics.uci.edu (Brett J. Vickers) writes: > > >void output_msgs() >{ > > while (current != NULL) { > printf("%s\n",current->string); > printf("&"); > > } > >} > >After the function has output its last message, it fails to continue >on to the next line (printf("&")). The ampersand isn't output until >the next call to output_msgs(). >Why is this happening? All help appreciated. The printf() function prints to stdout and the characteristics of the what's get printed depends on the what stdout points to. Assuming that the following program was run on UNIX and that stdout was directed to the terminal screen, the output will be line-buffered by default; nothing will print out until a newline occurs in the output (some implementations also flush output if a read from stdin is done). If stdout is redirected to a file, the output will be block buffered. The manual page setbuf() explains the normal conventions. If you want the output to print out even though you are not printing a newline, use fflush(stdout). Non-UNIX may or may not emulate the UNIX behavior (they may not be able to if they are unable to determine whether stdout points to a file or the terminal). Heather Burris, UCLA