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.

Chapter solution: Interpreting commands

Chapter solution: Interpreting commands - C Tutorial

From the course: Complete Guide to C Programming Foundations

Chapter solution: Interpreting commands

(bright music) - [Lecturer] For my solution to this chapter's challenge, I start by declaring two integer variables. (keyboard clicking) Integer variable done is already shown in the code here at line 12. The second integer is ch, which is used to read input. I hope you don't forget to declare the done variable and remember that the getchar function that reads input returns, integer values in the main loop, we need to prompt for input. (keyboard clicking) You can use any prompt. I chose to output the text command and this print F statement doesn't contain or output a new line. (keyboard clicking) To read input, I use getchar. The single character input is stored in integer variable ch. Variable ch can then be evaluated in a switch case structure. (keyboard clicking) The first case is R for moving right. I capture both the big and little R characters, output the text, move right then break. These statements can be copied and pasted and then edited for the left and back moves. The Q…

Contents