相关疑难解决方法(0)

strtol重用param

此代码似乎按预期工作,使用单个指针填充数字数组

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

int main(void)
{
    int arr[4], count = 0, i;
    char *p, s[32] = "  \t  10,  15  \n  ,20,   25  , ";

    p = s;
    do {
        arr[count++] = (int)strtol(p, &p, 10);
        while (isspace(*p) || *p == ',') p++;
    } while (*p);
    for (i = 0; i < count; i++) {
        printf("%d\n", arr[i]);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

在strtol中使用p作为param1(source)和&p作为param 2(第一个无效字符的地址)是有效的吗?

c pointers strtol

6
推荐指数
2
解决办法
480
查看次数

标签 统计

c ×1

pointers ×1

strtol ×1