Which C function can convert À, É to lower à, è?
I tried tolower() and towlower(), but both do not work.
Which C function can convert À, É to lower à, è?
I tried tolower() and towlower(), but both do not work.
You can use towlower function:
/* towlower example */
#include <stdio.h>
#include <wctype.h>
#include <wchar.h>
#include <stddef.h>
#include <locale.h>
int main () {
setlocale(LC_CTYPE, "");
int i=0;
wchar_t str[] = L"À TÉst String.\n";
wchar_t c;
while (str[i]) {
c = str[i];
putwchar (towlower(c));
i++;
}
return 0;
}
Output is:
à tést string.
"" The empty name says to select a locale based on environment variables.
The actual problem that you are facing here *(despite the preceding "Answers"), is that you have a Unicode string. *(Or, at the very least, some kind of DBCS = "Double-Byte Character Set.")
The standard functions of the "C" language were devised "in a much-earlier, much-simpler time," in which the only language-representation that needed to be considered was ASCII
, which assigned "every character that needed to be represented" into a set of 127 possible values. Nowhere in this picture were any "diacritical markings" such as these. In those simple times, "1 byte = 1 character."
In order to represent "real human(!)-language characters," it was necessary to adopt a far more flexible encoding format which might assign anywhere from 1 to 4 bytes to a single "character." (And, mind you, a consensus about "exactly how to do this" did not happen overnight!) In any case, the "original" library-routines that you are now using here are not "Unicode aware." (They never were designed to be, and they cannot now be retrofitted ...) Instead, alternate functions must be used.
Here's a good external web-page which gives a pretty good summary of the various issues that need to be considered when using C and C++:
http://www.cprogramming.com/tutorial/unicode.html
--- Edit:
When I said, "a consensus about exactly how to do this did not happen overnight," my comment was intended to have potentially far-reaching(!) implications. "Why is it necessary, even today, to say "encoding=UTF-8"
? This is why. "A single interpretation of 'how to interpret a multi-national sequence-of-bytes'" never did develop, and the "C" language, especially, "took it in the chin." There are more-than-one complete sets of library-functions in today's "C" runtime that you might need to use, in order to correctly handle your data.