【C语言】二级指针的用法


1 、二级指针一般在传参时使用

将形如1234abcd这样的字符串,分别提取整数1234和字符串abcd

#include <stdio.h>
#include <ctype.h>

int str2int(const char* str,const char** p)
{
    
    
        int r=0;
        while(isdigit(*str)){
    
    
                r=r*10+(*str-'0');//0-9的ASCII-‘0’得到的值就是其数字本身
                ++str;
        }
        *p=str;
        return r;
}
int main()
{
    
    
        const char* str=NULL;
        int n=str2int("1234abcd",&str);
        printf("n=%d,str=%s\n",n,str);
        return 0;
}

输出:
n=1234,str=abcd

猜你喜欢

转载自blog.csdn.net/chuhe163/article/details/104264841