#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    4
    Rep Power
    0

    how to prevent char input


    hi,
    i need the user to input an interger and then do some calculations on it, but i can't work out how to prevent them entering char, how would i do it?

    Code:
          printf("Please enter the number:\n");
          scanf("%d", &temp);
          fflush(stdin);
    // input validation here
    
    else ...
    thanks
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    you could collect it as a char and then use

    isdigit()

    and

    atoi()

    to ensure it is a number.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo