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
3 ответов
+ 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){
}
+ 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
+ 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