Below are my codes that convert large letters to small letters and vice versa.
#if SOL_2
char ch;
char diff = 'A' - 'a';
//int diff = 'A' - 'a';
fputs("input your string : ", stdout);
while ((ch = getchar()) != '\n') {
if (ch >= 'a' && ch <= 'z') {
ch += diff;
}
else if (ch >= 'A' && ch <= 'Z') {
ch -= diff;
}
else {}
printf("%c", ch);
}
#endif
Above codes, instead of char diff = 'A' - 'a'
, I used the int = 'A' -'a'
and the result was same. Therefore, I thought that using character can save memory since char
is one byte but int
is four bytes. I can't think other advantages of it.
I would appreciate it if you let me know other advantages of it.
And What is the main reason of using char
in order to store character values?
It is because of just memory size problem?