How to write own isnumber() function?

前端 未结 4 1272
我寻月下人不归
我寻月下人不归 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:35

    I'm not sure if you want to check if it's a number or a digit and argv[1] is of type char * not int so you should do something like that:

    bool isDigit(char *param)
    {   
        return (*param >= `0` && *param <= `9`)
    }
    
    bool isNumber(char *param)
    {   
        while (param)
        {
            if (!isDigit(param))
                return false;
           param++;
        }
        return true;
    } 
    

提交回复
热议问题