I am trying to copy char *
element to char *[]
array . I am taking each token
values and copying to another array . Here i am using strcpy
function , This is the C
code i have written :
#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;
}
I am getting segmentation fault on strcpy(*(output+i),token);
this line . What exactly i am missing here ? Anybody explain a little bit would be more helpful to understand .