Thread: new problem after not using fflush(stdin)

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    51

    new problem after not using fflush(stdin)

    This is my previous codes:
    Code:
    	printf("Please key in Sales Agent's code number>");/* Output statement*/
        scanf("%d", &num);
    	fflush(stdin);
    
    	while( !(num >= 1000 && num <= 9999) )/*if the condition is not true then print the error message*/
    	{
    		printf("\aInvalid code number! Please key in 4 digits code number.\n");
    		main();
    	}
    After changing fflush(stdin) to if ( (scanf("%d",&num) !=1)
    when i input a alphabet for variable num it will cause the problem to do a infinity loop.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Read this
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    51
    make me confusing .......
    before that just a single line code... Yet....
    Any other simple way?....
    i canT understand the codes ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Searching Into Files
    By St0rM-MaN in forum C Programming
    Replies: 12
    Last Post: 04-26-2007, 09:02 AM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. fflush(stdin)
    By mako in forum C Programming
    Replies: 23
    Last Post: 01-21-2006, 03:12 PM