Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!tut.cis.ohio-state.edu!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Strange C Problem Keywords: Linked Lists Message-ID: <9339@alice.UUCP> Date: 10 May 89 19:08:51 GMT References: <13812@paris.ics.uci.edu> Distribution: na Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 39 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; > } > 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(). I wouldn't be surprised to find that your terminal output is line-buffered. Try this: current = first_msg; while (current != NULL) { printf("%s\n",current->string); printf("&"); fflush(stdout); /* insert this line */ temp = current; current = current -> next; free (temp); } first_msg = NULL; last_msg = NULL; } -- --Andrew Koenig ark@europa.att.com