How to write own isnumber() function?

前端 未结 4 1269
我寻月下人不归
我寻月下人不归 2020-12-20 08:05

I\'m new to C and I\'m thinking how to write this function myself. I take a parameter from command line, so it is stored in argv array and I want to decide whether it is or

4条回答
  •  既然无缘
    2020-12-20 08:30

    How about trying like this:

    #include 
    
    if(isdigit(input))
    {
      return true;
    }
    else
    {
      return false;
    }
    

    OR more simple as H2CO3 commented:

     #define isnumber isdigit
    

    OR

    #include 
    #include 
    #include 
    int main () {
    
      //some code
      theChar = atoi(string[i]);
      if (isdigit(theChar)) {
        return true;
      }
      return 0;
    }
    

提交回复
热议问题