Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there multiple C functions for case-insensitive comparison

For comparing any strings without considering their case, there are various C library functions such as strcasecmp(), stricmp() and stricmpi(). What is the difference between these?

like image 630
userrp1519825 Avatar asked May 26 '14 13:05

userrp1519825


People also ask

How do you perform a case insensitive comparison of two strings?

The equalsIgnoreCase() method compares two strings, ignoring lower case and upper case differences. This method returns true if the strings are equal, and false if not. Tip: Use the compareToIgnoreCase() method to compare two strings lexicographically, ignoring case differences.

Which function is used to compare two strings ignoring their cases in C?

The strcasecmp() function compares, while ignoring differences in case, the string pointed to by string1 to the string pointed to by string2.

How does Strcasecmp work in C?

Description. The strcasecmp() function compares string1 and string2 without sensitivity to case. All alphabetic characters in string1 and string2 are converted to lowercase before comparison. The strcasecmp() function operates on null terminated strings.

How do you make C not case sensitive?

To make strcmp case-insensitive, use strcasecmp from #include <strings. h> . strcasecmp can be used in exactly the same way as strcmp. To make strncmp case-insensitive, use strncasecmp from #include <strings.


1 Answers

There are multiple ways to do many things primarily because the standards process lags behind implementations. People see the need for a function (in this case, case insensitive string comparison) and some compiler writers/library writers implement a function called strcmpi, while another group implements stricmp, while another group decides it is not necessary to implement it, while another group implements strcasecmp while another group implements strcmpnocase, etc. Years later, representatives from the various groups meet in mortal combat and the winner's implementation becomes part of the language. Meanwhile, the other implementations continue with the other-named methods and the language grows stronger/fragments/gains bloat (depending on your point of view).

like image 113
William Pursell Avatar answered Sep 28 '22 16:09

William Pursell