检查字符串是不是整数的函数(C语言)

/* to see whether this string is a positive integer    */
int check_str_isint(char *psrc)
{
    int num;
    char *p;

    p = psrc;
    num = 0;
    while((*p) != '\0')
    {
        if((*p) >= '0' && (*p) <= '9')
        {
            num *= 10;
            num += (*p) - '0';
            p++; continue;
        }

        return 0;/* the string contains char not belongs to 0-9 */
    }
    return 1;
    //return num;
}

 

posted @ 2013-04-14 05:50  ScottChiang  阅读(210)  评论(0)    收藏  举报