0

Jungle Camping Problem

#include <stdio.h> #include<string.h> int main() { char sound[20]; int i=0, word=1, a; char l[]="Grr", t[]="Rawr", s[]="Ssss", b[]="Chirp"; fgets(sound,sizeof (sound),stdin); while(sound[i] != '\0') { if(sound[i]==' ' || sound[i]=='\n' || sound [i]=='\t') { word++; } i++; } for(i=0;i<word;i++) { if(strcmp(sound,l)==0) { printf ("Lion "); } else if(strcmp(sound,t)==0) { printf ("Rawr "); } else if(strcmp(sound,s)==0) { printf ("Snake "); } else if(strcmp(sound,b)==0) { printf ("Bird "); } } return 0; } Using this but only the 2nd test case come as positive. Can u tell me the problem here

8th May 2020, 1:44 AM
Saaquib Motiwala
1 ответ
+ 1
Your code gives no output if you enter more than one animal sound. Ssss Ssss Rawr -> no output
9th May 2020, 4:38 PM
Denise Roßberg
Denise Roßberg - avatar