what is the standard to compare string and ignore case, one book said strcmpi but my linux has strcasecmp, what if any is the standard?
what is the standard to compare string and ignore case, one book said strcmpi but my linux has strcasecmp, what if any is the standard?
It's trivial to do it yourself:
Of course, when working with string literals it isn't quite so easy. Close though.Code:/* Change case to lower (strlwr) */ char *lower(char *s) { char *p = s; while (*p != '\0') { *p = tolower(*p); ++p; } return s; } int compare(char *s1, char *s2) { return strcmp(lower(s1), lower(s2)); }
My best code is written with the delete key.
@Prelude: I was going to comment on how inefficient your version is, but then I realised you'd left it as an exercise for the OP.
@chrismiceli: If you know your compilers, you could also try to #define your way out of the problem. But, I'd still recommend the creation of your own function.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]