dimanche 19 janvier 2020

If Loop for taking an input not working in C

I can't get the if statement to print out the "Hey ! Another James \n" line.

Why is this not working, it looks simple enough, lol what am I missing?

I want the message to print if I call myself James.

Thanks

# include < stdio.h >
# include < string.h >


int main (int argc , char ** argv )
{
char first_name [30];
printf (" Please enter your first name : ") ;
fgets ( first_name , 30 , stdin ) ;

if ( strcmp (first_name, "James") == 0)
printf ("Hey ! Another James \n") ;
else
printf ("Goodbye!\n") ;
}

Aucun commentaire:

Enregistrer un commentaire