Thread: Menu not working

  1. #1
    Registered User
    Join Date
    Mar 2004

    Menu not working

    This is in main, and loops, of course, until the user presses 'e'. For some reason though, it gets printed twice after it determines what button was pressed and goes and does what it's suppose too. Any ideas?

    	while(input != 'e'){
    		printf("Please make a selection:\n");
    		printf("a <id number> to enter a customer into queue\n");
    		printf("r to remove a customer from queue\n");
    		printf("c to get a count of customers\n");
    		printf("e to exit program\n");
    		input = getchar();
    		if(input == 'r'){
    			if(remCust() == 0)
    		else if(input == 'c'){
    			printf("Count: %d\n",countCust());
    		else if(input == 'a'){
    			scanf("%d", &id);
    			if(addCust(id) == 0)
    				printf("Not added\n");

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    input = getchar();
    while( fgetc( stdin ) != '\n' );
    You and this person should get together and have a "stuff in the input buffer" party.

    In your case, what's happening is you press eenter. So it sends two characers. e and then enter. That's what happens when you mix scanf with other things like getchar.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. embedded menu system
    By v_dave in forum C Programming
    Replies: 26
    Last Post: 03-14-2008, 02:27 PM
  2. Replies: 8
    Last Post: 01-18-2008, 04:06 AM
  3. Creating a menu system
    By ICool in forum C Programming
    Replies: 9
    Last Post: 09-17-2007, 12:18 PM
  4. Menu stuff
    By Shadow in forum C Programming
    Replies: 10
    Last Post: 04-28-2002, 09:05 AM
  5. quick question about C Dos text menu pgm i was doing
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 09-16-2001, 10:26 AM