Originally Posted by
algorism
I doubt it has anything to do with errno. That would be strange indeed.
What would be strange?
Code:
//Program in C
/* Using strchr() & strcmp()
* function(s) to do some conditional(s) */
#include <string.h>
#include <stdio.h>
int main() {
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.");
getchar();
} else {
perror("Sorry! That was Cat.");
getchar();
}
return(0);
}
This is compiled by gcc 5.4 on Ubuntu and run from terminal without any IDE
Code:
$ ./test
Hello! Which animal does meow sound? as
Sorry! That was Cat.: Success
So instead of Error 0 it prints Success