Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!xanth!nic.MR.NET!umn-cs!clark From: clark@umn-cs.CS.UMN.EDU (Robert P. Clark) Newsgroups: comp.lang.c Subject: RE: strange C Message-ID: <12726@umn-cs.CS.UMN.EDU> Date: 10 May 89 14:10:23 GMT Organization: University of Minnesota, Minneapolis Lines: 36 in article 19474 bvickers writes: : I've come across a very strange problem in one of my programs. I'll : list the function that's causing the problems and then discuss what : those problems are. : : Globals: struct msg_node *first_msg, *last_msg; : : void output_msgs() : { ... deleted : printf("%s\n",current->string); : printf("&"); ... deleted : } : : Now, this function is supposed to output all the messages that are on : the linked list from first to last. But something strange happens. : 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. : I believe that the program is working correctly, there really is no problem. The "&" is not printed until later, because output is buffered. Printing a "\n" - as in printf("%s\n",current->string); flushes the output buffer. The next call to printf("&"); is executed, but the buffer is not flushed until later. You can force the "&" to be printed by manually flushing the output buffer with a call to fflush(stdout); Bob Clark clark@umn-cs.cs.umn.edu