如何判断输入值是否不是数字?

我想创建一个程序,如果一个数字是奇数或偶数,但如果我输入一个字母,程序必须停止。我想要做的是创建一个if语句,它允许程序理解我输入的是数字还是其他东西。这就是代码。

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int a,b;

    printf("type a number ");
    scanf("%d", &a);
    printf("\n");

    if (a<0) //This is supposed to understand if what I typed is a number, but it's not correct at all.
    {
        printf("ERROR, YOU MUST TYPE A NUMBER, NOT LETTERS.");
        system("PAUSE \n");
        return 0;
    }

    b=(a%2);

    if (b != 0)
    {
        printf("it's an odd number! ");
        printf("\n\n");
        system("PAUSE");
        return 0;
    }
    else
    {
        printf("it's an even number! ");
        printf("\n\n");
        system("PAUSE");
        return 0;
    }
}

转载请注明出处:http://www.0591kyj.com/article/20230526/1500069.html