ID非公開
ID非公開さん
2021/1/21 14:00
1回答
この(2)のプログラミングの問題がわかりません。
この(2)のプログラミングの問題がわかりません。 出現するかどうか判定する方法がわからなくて詰まっています。 このプログラミングの問題の答えを教えてください。 char sentence[] = "This is a pen. That is an apple.";
#include<stdio.h> #include<string.h> int main(void) { char sentence[] = "This is a pen. That is an apple."; char str[32]; char *p; printf("文字を入力してください>>>"); scanf("%s",str); if((p=strstr(sentence,str)) == (char *)&sentence) { printf("%s->始まっている\n",str); }else { printf("%s->始まっていない\n",str); } return 0; } (1)はこのようになりました。
ベストアンサー
---(1)--- #include<stdio.h> #include<string.h> int main(void){ char s1[]="This is a pen. That is an apple."; char s2[16]; printf("str >"); scanf("%s",s2); if(strstr(s1,s2) == s1){ printf("%s -> begin",s2); }else{ printf("%s -> not begin",s2); } return 0; } ---(2)--- #include<stdio.h> #include<string.h> int main(void){ char s1[]="This is a pen. That is an apple."; char s2[16]; printf("str >"); scanf("%s",s2); if(strstr(s1,s2) != NULL){ printf("%s -> included",s2); }else{ printf("%s -> not included",s2); } return 0; }
質問者からのお礼コメント
教えていただき、誠にありがとうございます!!
お礼日時:1/23 17:26