I'm having some problem with my code. I need to use strtok() in c to output the words "Sing" and "Toy" (which are both in between the words "Due" and "De") in the string "Date WEEk Dae Due Toy De Dae i Date Due Sing De". I tried to use the if statement found in the code to explicitly output the words "Sing" and "Toy" but my code would not produce any output and it had no warnings during compilation. I'm only a beginner at C so please be patient with me. I heard that other functions such as strstr() might be able to do the same job as strtok() so if those other functions are much more convenient to use, do not hesitate to use those functions instead. Thank you. Summary: I'm trying to get the words in between "Due" and "De" in the string above using strtok() and is it possible to do so or should I use another function?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char string[]="Date WEEk Dae Due Toy De Dae i Date Due Sing De";
char*pch;
pch=strtok(string,"De");
while(pch!=NULL){
if((*(pch-1)=='a')&&(*(pch-2)=='u'))
printf("%s\n",pch);
pch=strtok(NULL,"De");
}
return 0;
}