0

How to make user input case-insensitive in C?

#include<stdio.h> int main() { char user[100]; char yes[3]; printf("what u name?\n"); scanf("%s",&user); printf("so you're %s? \n",&user); scanf("%s",&yes); if (&yes==yes) printf("nice!"); return 0; } This is the code

29th Mar 2023, 3:56 AM
Glitching shift Sans
Glitching shift Sans - avatar
3 Respostas
+ 1
you can either : use logical operator or || in the condition. (include <string.h> for strcpm) if(strcmp(yes,"yes") == 0 || strcmp(yes, "Yes") == 0){ } or : convert yes to lowercase before the condition ,that way you cover other combinations of yes then use if(strcmp(yes , "yes")==0){ }
29th Mar 2023, 5:49 AM
Bahha‚Ķ£
Bahha‚Ķ£ - avatar
+ 1
I think you compare the string through user input https://qnaplus.com/c-program-to-check-whether-two-strings-are-equal-in-case-insensitive-way/ Hope it's helpful to you
29th Mar 2023, 5:34 AM
Sakshi [Offline ūüôÉ]
Sakshi [Offline ūüôÉ] - avatar
+ 1
There was no easy way into this, advent of Unicode character sets and the various compiler/system builders implementation adds up to the confusion. https://stackoverflow.com/questions/23871403/why-are-there-multiple-c-functions-for-case-insensitive-comparison
29th Mar 2023, 10:12 AM
Ipang