Here is my code
Code:
//Program in C
/* Using strchr() & strcmp()
* function(s) to do some conditional(s) */
#include <string.h>
#include <stdio.h>
#include <conio.h>
main() {
clrscr();
char name[20];
char *ptr;
/* Taking an animal name from user */
printf("Hello! Which animal does meow sound? ");
fgets(name, 20, stdin);
if ((ptr = strchr(name, '\n'))) {
//Replacing newline with NULL
*ptr = '\0';
}
//Performing check on user input
char match[4] = "Cat";
if (strcmp(name, match) == 0) {
printf("Bravo! You are correct.");
getch();
} else {
perror("Sorry! That was Cat.");
getch();
}
return(0);
}
Prompt: Hello! Which animal does meow sound?
Input: Doggy
Output: Sorry! That was Cat.: Error 0
Why is Error 0 being displayed?
Please give me explanation.