C - verify fgets in some possibilities | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 4

C - verify fgets in some possibilities

const char *test[4] = {"one", "two", "three"}; fgets(my_str, 10, stdin); how can I check if my_str == "one" or "two" or "three" but not like that : ? if my_str=="one" || my_str=="two"...

4th Feb 2019, 7:45 PM
NoxFly
NoxFly - avatar
3 Antworten
+ 6
Hi NoxFly ŃâëŃâ¬ŃéóŃâ│ here try strcmp (http://www.cplusplus.com/reference/cstring/strcmp/) but remember fgets doesn't remove the "\n" from the buffer, so you have to clean it up manually, if you don't it will make comparison always wrong because of the "\n" ­čśü
4th Feb 2019, 8:20 PM
Ipang
+ 4
thanks I'll try :D
4th Feb 2019, 8:21 PM
NoxFly
NoxFly - avatar
+ 2
you can do this loop, length of array is small. Either you can use sorting.
5th Feb 2019, 3:08 AM
lk­čĹŻ