Thread: Testing user input question?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    North Liberty, IA
    Posts
    67

    Testing user input question?

    I have a program that requires a user to input a number. The number determines how many random numbers(done by my program) will be displayed on the screen. The number input by the user will be of type int. Is it legal to use an isalpha() function to test and see if it actually is an int. Eg. if someone types in 46i instead of 461. Would this be a correct way to check it. I'm not at my PC with my compiler right now so I'm just trying to get close.

    Code:

    Code:
    void get_info(char *filename, int *n_ptr)
    {
        prinf("\n%S\n\n%s",
    	"This progam creates a file of random numbers.",
    	"Please enter in the number of random numbers
                      you would like to see as a positive integer.   "),
        if (scanf("%d", n_ptr)) != 1 || n_ptr <=0 || isalpha(n_ptr)
            {
                printf("\nERROR: Please enter positive integer.\n");
             }
        
         printf("\nIn what file would you like them?  ");
         scanf("%s", filename);
    }
    Thanks for any help.
    Last edited by Hoser83; 02-15-2006 at 08:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with error checking on input from user.
    By NuNn in forum C Programming
    Replies: 8
    Last Post: 01-23-2009, 12:59 PM
  2. Replies: 4
    Last Post: 04-03-2008, 09:07 PM
  3. newbie question regarding user input
    By cantore in forum C Programming
    Replies: 4
    Last Post: 03-05-2006, 08:57 PM
  4. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 06:01 AM
  5. Beginner question- user input termination
    By westm2000 in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 02:48 PM