I
I
Iqv2016-02-01 20:58:09
Programming
Iqv, 2016-02-01 20:58:09

How to check if you entered a letter in C?

There is a program that asks for 3 numbers, it is in a loop. And how can I make the program display the inscription "ERROR" when a letter is entered?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RedHairOnMyHead, 2016-02-01
@ThePyzhov

You read each number into a string, in a loop you check each character and if the check passes, then translate the drain into a number.

while(*p) {
    if(!isdigit(*p++)) {
        isd=false;
        break;
    }
}
if(isd)
    digit=atoi(str);
else
    printf("\nERROR\n");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question