verify input

This is a discussion on verify input within the C Programming forums, part of the General Programming Boards category; How would I verify a users input? Like say the had to enter a number, and they entered a character, ...

  1. #1
    Unregistered
    Guest

    verify input

    How would I verify a users input? Like say the had to enter a number, and they entered a character, how would you check that?

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    You can check that manually by doing some Ascii arithmetic or use functions such as isalpha(), isdigit()....etc by including ctype.h

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Prelude has written a validate function, do a board search to find it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > How would I verify a users input?
    There are several, several ways.

    > Like say the had to enter a number, and they entered a character, how would you check that?
    One of the many ways, and easiest to catch on to:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int menu(void);
    
    int main(void)
    {
    	char choice;
    	while(menu() == 0)
    	{
    		choice=getch();
    		switch(choice)
    		{
    			case '1':
    			printf("\n\nThe user entered the number 1");
    			printf("\n\nPress any key..");
    			getch();
    			break;
    
    			case 'b':
    			printf("\n\nThe user entered the letter b.");
    			printf("\n\nPRess any key..");
    			getch();
    			break;
    			
    			case 27:
    			printf("\n\nClosing..");
    			return 0;
    			break;
    			
    			default:
    			printf("\n\nThe user entered an invalid selection");
    			break;
    		}
    	}
    	return 0;
    }
    
    int menu(void)
    {
    	printf("\n\n1.  Print message for character confirmation\n");
    	printf("B.  Print message for character confirmation\n");
    	printf("Anything else - default message\n\n");
    	printf("Escape exits");
    	return 0;
    }
    The world is waiting. I must leave you now.

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

  6. #6
    Unregistered
    Guest
    thanks everyone

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 02:59 AM
  2. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 04:54 AM
  3. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 04:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21