Path: utzoo!attcan!uunet!lll-winken!ames!purdue!haven!rutgers!rochester!pt.cs.cmu.edu!cadre!pitt!cisunx!jcbst3 From: jcbst3@cisunx.UUCP (James C. Benz) Newsgroups: comp.lang.c Subject: Re: Strange C Problem Keywords: Linked Lists Message-ID: <18006@cisunx.UUCP> Date: 11 May 89 14:40:46 GMT References: <13812@paris.ics.uci.edu> Reply-To: jcbst3@unix.cis.pittsburgh.edu (James C. Benz) Distribution: na Organization: Univ. of Pittsburgh, Comp & Info Sys Lines: 46 In article <13812@paris.ics.uci.edu> bvickers@bonnie.ics.uci.edu (Brett J. Vickers) writes: > current = first_msg; > while (current != NULL) { > printf("%s\n",current->string); > printf("&"); > temp = current; > current = current -> next; > free (temp); > } > first_msg = NULL; > last_msg = NULL; >} >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(). In case nobody has answered this yet, (unlikely, but I'm gonna do it anyway) First, your line that prints the string has a \n in it. It is followed by a printf that prints a single (special!) character WITHOUT a newline. The way your loop is set up, this second printf executes after EACH string from the linked list is output, not after the whole list. Further, since no newline is output following the printf("&") the output buffer is not flushed (stdout is only flushed on receipt of a newline. Stderr is flushed on each character) So when the last printf("&") is executed, it waits in the stdout buffer until the next call to printf("%s\n",.....), which is only when you call output_msg again. Try putting a printf("\n") OUTSIDE the loop before exiting the function. Or look up fflush in the manual. Newsgroups: comp.lang.c Subject: Re: mutual reference in structures Summary: Expires: References: <6712@medusa.cs.purdue.edu> <539@lakart.UUCP> Sender: Reply-To: jcbst3@unix.cis.pittsburgh.edu (James C. Benz) Followup-To: Distribution: Organization: Univ. of Pittsburgh, Comp & Info Sys Keywords: -- Jim Benz jcbst3@unix.cis.pittsburgh.edu If a modem University of Pittsburgh answers, UCIR (412) 648-5930 hang up!