View Single Post
  #8 (permalink)  
Old 04-17-2007, 08:45 AM
v0id's Avatar   
v0id v0id is offline
<img src="http://forum.codecall.net/images/userbar/supermod.png" alt="Super Moderator">
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,468
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

You're still missing to flush the standard input stream, before starting the while-loop over again. You have to insert a fflush()-function in the start of the while-loop or at the end of it. If you're looking at the last code I posted in this thread, you can see that there's two fflush()-functions, not only one.

The reason why you have to insert one, is because that after you have selected something in the menu, and again inputs something - f.ex. CHAR => ASCII, then the stdin get new data again - and that data, we've to clear. That's by using the fflush()-function at stdin. If you read my comments in the code, you could see it too.

Code:
#include <stdio.h>

int main()
{
	int  i, type;
	char c;
	type = 0;
	
	printf("ASCII character program\n\n");
	while(type != 'q')
	{
		/* Here's all the other stuff ... */
		

		/* At the end, we need to have this */
		fflush(stdin);
	}
	
	return 0;
}
Reply With Quote