Strange C Problem
Andrew Koenig
ark at alice.UUCP
Thu May 11 05:08:51 AEST 1989
In article <13812 at paris.ics.uci.edu>, bvickers at 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 at europa.att.com
More information about the Comp.lang.c
mailing list