3

I need to convert my string into int array. so i make a loop over string, and call int atoi(char *p) function from stdlib.h, but it doesn`t working on mac (some times ago i tryed it on Windows, and it workong well). simple loop:

    for(p = buff; *p; p++)
    printf("%d", atoi(p));

whats the problem with work of this function, u think?

4

1 回答 1

5

该功能运行良好。例如,如果buff包含"123",您的代码将打印123233

但是,您似乎只想打印单个数字的值,在这种情况下atoi与您的问题无关。尝试:

for(p = buff; *p; p++)
    printf("%d", *p-'0');
于 2012-05-14T12:43:29.887 回答