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

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