/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
Gabriel Staples
www.ElectricRCAircraftGuy.com
25 July 2020
See also:
1. (my answer for case-insensitive-string-comp in C, for ASCII chars only)
https://stackoverflow.com/questions/5820810/case-insensitive-string-comp-in-c/55293507#55293507
1. (note this is C++, not C):
https://stackoverflow.com/questions/34433380/lowercase-of-unicode-character
NOTE: COPY THE OUTPUT OF THIS PROGRAM TO THE CLIPBOARD AND LOOK AT IT IN A TEXT
EDITOR, SUCH AS SUBLIME TEXT 3, TO BE ABLE TO SEE AND ANALYZE ALL OUTPUT AT
ONCE.
*******************************************************************************/
#include <ctype.h> // for `tolower()`
#include <stdio.h>
int main()
{
printf("Hello World\n\n");
printf("Printing `tolower()` values of all possible char (int8_t) values!\n\n");
char c = -128;
char c_lower;
for (;;)
{
printf("c = (number) % 4i; (unsigned char) %3u; (char) %c\n",
c, (unsigned char)c, c);
c_lower = tolower(c);
printf("c_lower = (number) % 4i; (unsigned char) %3u; (char) %c\n\n",
c_lower, (unsigned char)c_lower, c_lower);
if (c == 127)
{
break;
}
c++;
}
printf("======================================================================\n\n");
printf("Testing some other random strings with `tolower()`.\n\n");
// See: https://stackoverflow.com/questions/34433380/lowercase-of-unicode-character
const char * const s = "Đ Â Ă Ê Ô Ơ Ư Ấ Ắ Ế Ố Ớ Ứ Ầ Ằ Ề Ồ Ờ Ừ Ậ Ặ Ệ Ộ Ợ Ự ß";
const char* s_p; // pointer to C string
// Print it now
printf("%s\n--------\n", s);
// Print it again
printf("tolower():\n");
s_p = s;
while (*s_p)
{
printf("%c", tolower(*s_p));
s_p++;
}
printf("\n--------\n");
// Print it now again.
// OBSERVE: each of these funky (unicode?) chars is actually **2 bytes**!
// You can see this in the output, as two (usually/always negative) bytes
// print out first, followed by a decimal 32, which is the space between
// each char!
s_p = s;
while (*s_p)
{
c = *s_p;
c_lower = tolower(c);
// printf("%c", tolower(*s_p));
printf("%c, %c\n", *s_p, tolower(*s_p));
printf("%c, %c\n", c, c_lower);
printf("c = (number) % 4i; (unsigned char) %3u; (char) %c\n",
c, (unsigned char)c, c);
char c_lower = tolower(c);
printf("c_lower = (number) % 4i; (unsigned char) %3u; (char) %c\n\n",
c_lower, (unsigned char)c_lower, c_lower);
// printf("%c", tolower(*s_p));
s_p++;
}
printf("\n");
return 0;
}