I have a c code that tokenize the content of my file. I want to copy/assign each token to a temp variable to put it into a list. My temp was declared as char *temp[MAX]. Here is my code but there is something wrong in strcpy(temp[k], token). When i run my code, it force close my program. However, when I remove the strcpy line/statement, it runs correctly and does not force close. But my goal to copy the tokens to temp will not be done. Can somebody know why this is happening? Thank you.
Declaration of temp is global: char *temp[MAX]
;
void tokenize(FILE *input){
char *token;
int k=0;
char word[1000];
while(!feof(input)){
fgets(word,1000,input);
token = strtok(word, " \t\n");
while(token!=NULL){
printf("%s\n",token);
strcpy(temp[k], token);
k++;
token= strtok(NULL, " \t\n");
}
}
printf("%s", temp[0]);
}