From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Character I/O and conversions - C Tutorial
From the course: Complete Guide to C Programming Foundations
Solution: Character I/O and conversions
(light music) - [Instructor] Here is my solution, the bulk of which takes place in this while loop. I use an if else, if else decision tree to convert between upper and lowercase at line 12. If the character is uppercase, output its lowercase counterpart. It uses two C type conversions is upper and two lower. These statements don't convert the character in the string. They only change the output. The next test takes place at line 14 when the character is lowercase output its uppercase equivalent. The is lower and two upper functions are used. Here again to upper only changes the output. It does not alter the original string and then the else condition handles all other characters in the string as is. Something that's easily forgotten in a while loop here at line 18. Always remember to trigger the exit condition. Variable X is incremented here to do so. It also prevents the loop from spewing out the letter N endlessly. That's happened to me a few times. Let's run to see how it works…
Contents
-
-
-
-
-
-
-
-
-
Using single character I/O3m 32s
-
(Locked)
Testing and converting characters3m 15s
-
(Locked)
Challenge: Character I/O and conversions34s
-
(Locked)
Solution: Character I/O and conversions1m 37s
-
(Locked)
Understanding strings in C2m 46s
-
(Locked)
Fetching string input3m 45s
-
(Locked)
Sending string output3m 41s
-
(Locked)
Challenge: Using printf placeholders1m 9s
-
(Locked)
Solution: Using printf placeholders1m 59s
-
(Locked)
Exploring string functions2m 41s
-
(Locked)
Manipulating strings2m 57s
-
(Locked)
Chapter challenge: Reading commands1m 52s
-
(Locked)
Chapter solution: Reading commands2m 31s
-
-
-
-
-