将char *复制到Char * []数组时出现分段错误

时间:2018-01-05 08:00:54

标签: c arrays segmentation-fault

我正在尝试将char *元素复制到char *[]数组。我正在获取每个token值并复制到另一个数组。我在这里使用strcpy函数,这是我写的C代码:

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

int main()
{
    char input[20];
    char *output[20];
    char *token = NULL;
    int count = 0,i=0;
    printf("Enter the input string\n");
    scanf("%s",input);
    token = strtok(input,",");
    while(NULL != token)
    {
        strcpy(*(output+i),token);
        i++;
        count++;
        token = strtok(NULL,",");
    }
    return 0;
}

我在此行strcpy(*(output+i),token);上遇到分段错误。我到底错过了什么?任何人解释一下会更有帮助理解。

0 个答案:

没有答案
相关问题