<center>http://66.media.tumblr.com/0abe21b481c44032d3c4e0beedf6759b/tumblr_inline_neu6fx1e1F1t32je4.jpg [Image source](http://luxloop.tumblr.com/post/102336117692/on-art-and-coding)</center> Hey guys! Here is a quick little programming tip about going from uppercase to lowercase, or lowercase to uppercase in a C or C++ string. Honestly, you can change a character to whatever character you want if you know the ASCII values. Here is an ASCII table: http://www.asciitable.com/index/asciifull.gif [Image source](http://www.asciitable.com) We are comparing the "Dec" column to the "Chr" column (decimal to character). Notice how each corresponding decimal number of an uppercase letter is 32 less than the number of its lowercase match. So to change a letter from uppercase to lowercase, all that we need to do is add 32: ``` char c = 'A'; printf("%c\n", c); c += 32; printf("%c\n", c); ``` Output: ``` A a ``` Going the other way: ``` char c = 'a'; printf("%c\n", c); c -= 32; printf("%c\n", c); ``` Output: ``` a A ``` It is that simple! Here is a program I wrote that changes all lowercase values in a string to uppercase: ``` #include<stdio.h> #include<string.h> int main() { printf("Enter a sentence (50 char max): "); char input[50]; fgets(input, 50, stdin); int x; for(x = 0; x < strlen(input); x++) if(input[x] > 96 && input[x] < 123) // only change if it is lowercase -- from 97 to 122 input[x] -= 32; printf("%s", input); return 0; } ``` Output: ``` [cmw4026@omega test]$ gcc upper.c [cmw4026@omega test]$ ./a.out Enter a sentence (50 char max): I like EATING dogs? I LIKE EATING DOGS? [cmw4026@omega test]$ ``` I hope that was useful! It is important to understand how ASCII characters work in my opinion. Leave any suggestions in the comments.
author | charlie.wilson |
---|---|
permlink | easy-programming-tip-change-a-string-to-uppercase-lowercase-ascii-c-and-c-beginner-friendly |
category | programming |
json_metadata | {"tags":["programming","tutorial","beginner","ascii","characters"],"image":["http://66.media.tumblr.com/0abe21b481c44032d3c4e0beedf6759b/tumblr_inline_neu6fx1e1F1t32je4.jpg","http://www.asciitable.com/index/asciifull.gif"],"links":["http://luxloop.tumblr.com/post/102336117692/on-art-and-coding","http://www.asciitable.com"]} |
created | 2016-10-18 05:42:42 |
last_update | 2016-10-18 05:42:42 |
depth | 0 |
children | 5 |
last_payout | 2016-11-18 09:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 39.951 HBD |
curator_payout_value | 11.920 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,781 |
author_reputation | 18,779,183,062,076 |
root_title | "Easy Programming Tip -- change a string to uppercase/lowercase (ASCII) C and C++ (beginner friendly)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 1,562,053 |
net_rshares | 55,102,240,452,399 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
anonymous | 0 | 175,603,125,156 | 61% | ||
val-a | 0 | 19,270,401,933,429 | 75% | ||
val-b | 0 | 2,201,544,891,072 | 13% | ||
ned | 0 | 8,453,176,481,548 | 13% | ||
riverhead | 0 | 6,719,400,677,600 | 100% | ||
pharesim | 0 | 4,746,169,239,045 | 50% | ||
kushed | 0 | 1,730,606,753,460 | 40% | ||
wang | 0 | 1,452,908,334,166 | 61% | ||
clayop | 0 | 3,892,387,065,271 | 75% | ||
joseph | 0 | 329,456,701,418 | 13% | ||
donkeypong | 0 | 919,959,615,060 | 37% | ||
gavvet | 0 | 1,553,090,485,755 | 100% | ||
steemship | 0 | 399,684,925,176 | 50% | ||
cryptoctopus | 0 | 1,226,922,250,866 | 100% | ||
jesusislord | 0 | 428,108,905 | 100% | ||
murh | 0 | 1,706,152,427 | 15.09% | ||
gore84 | 0 | 8,874,917,278 | 100% | ||
beerbloke | 0 | 9,836,284,433 | 13% | ||
justtryme90 | 0 | 106,880,990,931 | 100% | ||
coinbitgold | 0 | 151,614,610,740 | 100% | ||
anwenbaumeister | 0 | 466,268,312,613 | 50% | ||
grandpere | 0 | 10,828,197,965 | 70% | ||
globeskeptic | 0 | 234,197,813 | 100% | ||
anyx | 0 | 226,321,670,761 | 35% | ||
gikitiki | 0 | 10,690,206,765 | 100% | ||
febird | 0 | 8,608,447,226 | 100% | ||
tarindel | 0 | 8,494,676,875 | 100% | ||
greengo | 0 | 615,722,839 | 100% | ||
qonq99 | 0 | 541,751,733 | 100% | ||
cheetah | 0 | 17,634,668,826 | 35% | ||
steemster1 | 0 | 115,686,460 | 100% | ||
sharon | 0 | 52,489,886 | 100% | ||
lillianjones | 0 | 52,114,341 | 100% | ||
msjennifer | 0 | 52,526,031 | 100% | ||
ciao | 0 | 52,112,432 | 100% | ||
steemo | 0 | 50,521,096 | 100% | ||
steema | 0 | 50,390,768 | 100% | ||
confucius | 0 | 56,710,736 | 100% | ||
jarvis | 0 | 51,166,070 | 100% | ||
rubenalexander | 0 | 18,830,746,971 | 100% | ||
fortuner | 0 | 50,692,212 | 100% | ||
kyriacos | 0 | 45,018,996,071 | 100% | ||
lemouth | 0 | 26,980,748,896 | 100% | ||
alexma3x | 0 | 234,844,499 | 20% | ||
johnbyrd | 0 | 50,698,107 | 100% | ||
thomasaustin | 0 | 50,682,252 | 100% | ||
thermor | 0 | 50,680,459 | 100% | ||
ficholl | 0 | 50,691,211 | 100% | ||
movievertigo | 0 | 72,184,657,420 | 100% | ||
revelbrooks | 0 | 50,311,250 | 100% | ||
mandibil | 0 | 89,478,787,438 | 100% | ||
curpose | 0 | 50,416,427 | 100% | ||
ats-david | 0 | 12,841,616,558 | 100% | ||
krnel | 0 | 104,094,476,163 | 100% | ||
troich | 0 | 50,588,612 | 100% | ||
crion | 0 | 50,593,879 | 100% | ||
hitherise | 0 | 50,271,139 | 100% | ||
wiss | 0 | 50,262,756 | 100% | ||
ajaub1962 | 0 | 3,308,333,028 | 100% | ||
stroully | 0 | 51,033,798 | 100% | ||
doitvoluntarily | 0 | 17,718,744,065 | 100% | ||
thadm | 0 | 50,712,038 | 100% | ||
prof | 0 | 50,710,305 | 100% | ||
yorsens | 0 | 50,370,757 | 100% | ||
bane | 0 | 50,065,875 | 100% | ||
vive | 0 | 50,059,754 | 100% | ||
coad | 0 | 50,054,445 | 100% | ||
sofa | 0 | 50,840,303 | 100% | ||
waldemar-kuhn | 0 | 519,494,086 | 100% | ||
ailo | 0 | 50,933,404 | 100% | ||
burnin | 0 | 11,028,377,218 | 100% | ||
anomaly | 0 | 749,414,759 | 100% | ||
eavy | 0 | 50,441,122 | 100% | ||
roto | 0 | 50,454,901 | 100% | ||
drac59 | 0 | 571,369,403 | 100% | ||
robotev1 | 0 | 54,837,883 | 20% | ||
robotev2 | 0 | 54,694,630 | 20% | ||
robotev | 0 | 2,336,984,122 | 20% | ||
crimson | 0 | 527,984,054 | 75% | ||
grisha-danunaher | 0 | 10,728,272,460 | 100% | ||
igtes | 0 | 55,024,265 | 100% | ||
curie | 0 | 163,664,130,924 | 50% | ||
buffett | 0 | 112,778,207 | 100% | ||
ariugrakazshura | 0 | 151,110,433 | 100% | ||
comeup | 0 | 57,650,267 | 20% | ||
charlie.wilson | 0 | 6,959,489,948 | 100% | ||
techslut | 0 | 22,291,478,696 | 100% | ||
oshima | 0 | 352,899,330 | 50% | ||
qagiri | 0 | 1,901,649,848 | 100% | ||
thoughts-in-time | 0 | 466,301,925 | 100% | ||
sochul | 0 | 310,964,660,974 | 100% | ||
thegoodvybe | 0 | 68,090,270 | 100% | ||
elefandy | 0 | 989,017,692 | 100% | ||
technocomanche | 0 | 250,168,754 | 100% | ||
adelja | 0 | 124,043,457 | 100% | ||
andryusha | 0 | 469,665,688 | 100% | ||
bexy | 0 | 130,671,240 | 100% | ||
sqube | 0 | 73,431,560,779 | 51% |
@charlie.wilson Playing around with ASCII is cool Thanks for sharing this.
author | qagiri |
---|---|
permlink | re-charliewilson-easy-programming-tip-change-a-string-to-uppercase-lowercase-ascii-c-and-c-beginner-friendly-20161018t060354347z |
category | programming |
json_metadata | {"tags":["programming"],"users":["charlie.wilson"]} |
created | 2016-10-18 06:06:33 |
last_update | 2016-10-18 06:06:33 |
depth | 1 |
children | 1 |
last_payout | 2016-11-18 09:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 74 |
author_reputation | 5,207,321,068,642 |
root_title | "Easy Programming Tip -- change a string to uppercase/lowercase (ASCII) C and C++ (beginner friendly)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 1,562,126 |
net_rshares | 6,959,489,948 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
charlie.wilson | 0 | 6,959,489,948 | 100% |
No problem, thanks for reading!
author | charlie.wilson |
---|---|
permlink | re-qagiri-re-charliewilson-easy-programming-tip-change-a-string-to-uppercase-lowercase-ascii-c-and-c-beginner-friendly-20161018t065033478z |
category | programming |
json_metadata | {"tags":["programming"]} |
created | 2016-10-18 06:50:33 |
last_update | 2016-10-18 06:50:33 |
depth | 2 |
children | 0 |
last_payout | 2016-11-18 09:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 31 |
author_reputation | 18,779,183,062,076 |
root_title | "Easy Programming Tip -- change a string to uppercase/lowercase (ASCII) C and C++ (beginner friendly)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 1,562,365 |
net_rshares | 0 |
Would it be difficult to program a Pidgin plugin that sends the text displayed to the windows clipboard? It would be cool if pidgin could talk, and most TTS has a clipboard monitor.
author | thoughts-in-time |
---|---|
permlink | re-charliewilson-easy-programming-tip-change-a-string-to-uppercase-lowercase-ascii-c-and-c-beginner-friendly-20161018t064211638z |
category | programming |
json_metadata | {"tags":["programming"]} |
created | 2016-10-18 06:42:12 |
last_update | 2016-10-18 06:42:12 |
depth | 1 |
children | 2 |
last_payout | 2016-11-18 09:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 181 |
author_reputation | 59,797,459,104,031 |
root_title | "Easy Programming Tip -- change a string to uppercase/lowercase (ASCII) C and C++ (beginner friendly)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 1,562,303 |
net_rshares | 6,959,489,948 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
charlie.wilson | 0 | 6,959,489,948 | 100% |
Probably not, but I have never tried it... It sounds simple enough.
author | charlie.wilson |
---|---|
permlink | re-thoughts-in-time-re-charliewilson-easy-programming-tip-change-a-string-to-uppercase-lowercase-ascii-c-and-c-beginner-friendly-20161018t065120922z |
category | programming |
json_metadata | {"tags":["programming"]} |
created | 2016-10-18 06:51:21 |
last_update | 2016-10-18 06:51:21 |
depth | 2 |
children | 1 |
last_payout | 2016-11-18 09:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 67 |
author_reputation | 18,779,183,062,076 |
root_title | "Easy Programming Tip -- change a string to uppercase/lowercase (ASCII) C and C++ (beginner friendly)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 1,562,370 |
net_rshares | 466,301,925 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
thoughts-in-time | 0 | 466,301,925 | 100% |
If it seems interesting I'd be a willing guinea pig to try it out. It also could make for a fun programming post.
author | thoughts-in-time |
---|---|
permlink | re-charliewilson-re-thoughts-in-time-re-charliewilson-easy-programming-tip-change-a-string-to-uppercase-lowercase-ascii-c-and-c-beginner-friendly-20161018t070317459z |
category | programming |
json_metadata | {"tags":["programming"]} |
created | 2016-10-18 07:03:18 |
last_update | 2016-10-18 07:03:18 |
depth | 3 |
children | 0 |
last_payout | 2016-11-18 09:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 113 |
author_reputation | 59,797,459,104,031 |
root_title | "Easy Programming Tip -- change a string to uppercase/lowercase (ASCII) C and C++ (beginner friendly)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 1,562,431 |
net_rshares | 0 |