I'm trying compare two strings with the function srtcmp but do not get the result i want. The program is coded in C and should print the name of the user only if is older and male. Any case, only else instructions are executed.
#include <stdio.h>
#include <string.h>
int main() {
char name[20], sex[15];
int age;
printf("\n Your name here: "); fgets(name, 21, stdin);
printf(" Your sex here: "); fgets(sex, 16, stdin);
printf(" You age here: "); scanf("%i", &age);
if(strcmp(sex, "male")==0 && age>=18) {
printf("\n %s you are old.\n\n", name);
}
else {
printf("\n You are not old.\n\n");
}
return 0;
}