I am trying to tokenize a File and insert certain strings into an array. When I tokenize the file and print out each token, it works fine, but when I put each token into an array and print out the contents of the array, the contents are not the same at all.
char *filenames[1000];
token = strtok(line, " ");
while (token != NULL) {
printf("%s\n", token);
/*
filenames[i] = token;
i++;
*/
token = strtok(NULL, " ");
}
ck = fgets(line, 1000, fp);
for (j = 0; j <= i; j++){
printf("%s \n", filenames[j]);
}
Am I supposed to malloc the array of filenames, or malloc each token?