Thread: New to C
View Single Post
Old Feb 23rd, 2005, 10:55 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Use a method like this...

#include <stdio.h>

int getInt(char *msg);

int main(int argc, char *argv[]) {
    int num = getInt("Please enter a number: ");
    printf("You entered %d, thank you!", num);
    return 0;
}

int getInt(char *msg) {
    int num;

    try {
        printf(msg);
        scanf("%d", &num);
    } catch(char * errStr) getInt(msg);

    return num;
}
__________________

tempest is offline   Reply With Quote