0

Result says timeout but code is correct

You are given the noises made by different animals that you can hear in the dark, evaluate each noise to determine which animal it belongs to. Lions say 'Grr', Tigers say 'Rawr', Snakes say 'Ssss', and Birds say 'Chirp' Sample Input: Rawr Chirp Ssss Sample Output: Tiger Bird Snake Here is my code ;- #include<stdio.h> #include<string.h> int main() { char p=getchar(); int q=0; while(p!='\n') { char s[100]; scanf("%s",&s); if(q==0){ char str[100]; str[0]=p; strncat(str,s,strlen(s)); strcpy(s,str); } int a=strcmp(s,"Grr"); int b=strcmp(s,"Rawr"); int c=strcmp(s,"Ssss"); int d=strcmp(s,"Chrip"); // printf("%d",c); if(a==0) printf("Lion "); else if(b==0) printf("Tiger "); else if(c==0) printf("Snake "); else if(d==0) printf("Bird "); q=1; p=getchar(); }}

3rd Jun 2022, 2:50 AM
Nikunj Navdiya
Nikunj Navdiya - avatar
3 Answers
0
The why program cause 'Time out' is happened when you made infinity loop like while(true)
3rd Jun 2022, 4:16 AM
SorryPark
0
Got it but i have to use it
3rd Jun 2022, 4:26 AM
Nikunj Navdiya
Nikunj Navdiya - avatar
0
Is there any other option for this program?
3rd Jun 2022, 4:26 AM
Nikunj Navdiya
Nikunj Navdiya - avatar