how to check if the input is a number or not in C?

前端 未结 8 2075
暖寄归人
暖寄归人 2020-11-27 05:38

In the main function of C:

void main(int argc, char **argv)
{
   // do something here
}

In the command line, we will type any number for ex

8条回答
  •  隐瞒了意图╮
    2020-11-27 06:07

    Another way of doing it is by using isdigit function. Below is the code for it:

    #include 
    #include 
    #include 
    #include 
    #define MAXINPUT 100
    int main()
    {
        char input[MAXINPUT] = "";
        int length,i; 
    
        scanf ("%s", input);
        length = strlen (input);
        for (i=0;i

提交回复
热议问题