0

How to compare two pointers (with chars) in C

I have this code char* word[50] = {"hi", "hello", "dog"}; char word2[50]; fgets(word,50, stdin); getchar(); for example, I if the user enters "greetings", I want to output "hi", if the user enters "greeting2" I want to output "hello" if the user enters "animal", will print dog. but I don't know how to do that, I have tried a lot and I can't. Any idea about how to do that?

22nd Oct 2018, 7:58 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
1 Resposta
0
strcmp is your friend. fgets(word2, 50, stdin); if (strcmp(word2, "greetings") == 0) fputs(stdin, word[0) else if....
25th Oct 2018, 7:51 PM
Vlad Serbu
Vlad Serbu - avatar