ベストアンサー
(1150594305さん) 例: #include <stdio.h> #include <string.h> #include <ctype.h> void allUpper(char *a){ while(*a){ *a=toupper(*a); a++; } } int main(void){ char s[256]; char k[32]; char *p,*q; int i=1,n; printf("sentence >"); fgets(s,256,stdin); printf("key word >"); scanf("%s",k); s[strlen(s)-1]='\0'; allUpper(s); allUpper(k); p=q=s; while(1){ q=strtok(p," "); if(q==NULL)break; p=NULL; if(strcmp(q,k)==0){ puts("found"); return 0; } } puts("not found"); return 0; } ~~~~~~~~~~~~~~~~~~~~~~~~~ sentence >Think for yourself a little bit key word >For found sentence >Think for yourself a little bit key word >hoge not found
質問者からのお礼コメント
助かりました。これでまた一つ勉強になりました。 ありがとうございます。
お礼日時:5/22 1:20