为了弄懂sprintf,我写了这个程序,是不是很幼稚。

同时也是为了理解指针的指针,所以写了如下程序并调试之。

#include <stdio.h>

int is_digit(char c) ;

int main (int argc, char *argv[]) {
    int i;
    for (i = 0; i < argc; i++)
        printf ("%s\n", *argv++);

    char *str = "65535";
    
    char **s;
    s = &str;

    i = 0;

    while (is_digit(**s)) {

        i = i * 10 + *((*s)++) - '0';
    }
    
    printf ("\n");
    printf ("%d\t %x\n", i, i);


}

int is_digit(char c) {
    if (c >= '0' && c <= '9') {
        return 1;
    } else {
        return 0;        
    }

}

猜你喜欢

转载自blog.csdn.net/weixin_39410618/article/details/82709584