i am reading from file called inputfile and storeing in char array line. Lets say the word in char array line is "black cat". than I am strtok word "black" and puting in ch. After that iam testing if the 1st word is black or not. Inside the if statment iam getting the 2nd word by using sttok, so tptr will have "cat". than iam using strcpy and strcat so than char array called name will have "black cat and dog".
Problem: problem iam haveing on line
tptr = strtok(NULL," ");
To me it look fine and i am not sure what iam doing wrong. any troughs?
while(fscanf(inputfile, "%s", line)) != EOF)
{
if(tptr != NULL)
{
strcpy(ch, tptr);
if(strcmp(ch, "black") == 0)
{
tptr = strtok(NULL," ");
strcpy(name, tptr);
strcat(name," and dog");
}
}
}