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 - 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
-
-
-
-
-
-
Making a decision3m 25s
-
(Locked)
Exploring the possibilities2m 53s
-
(Locked)
Using the ternary operator3m
-
Working with the switch-case structure4m
-
(Locked)
Challenge: Select an item28s
-
(Locked)
Solution: Select an item1m 45s
-
Creating a for loop3m 36s
-
(Locked)
Setting up a while loop2m 58s
-
(Locked)
Challenge: Repeat some text51s
-
(Locked)
Solution: Repeat some text1m 51s
-
(Locked)
Nesting loops1m 59s
-
(Locked)
Breaking out of a loop3m 16s
-
(Locked)
Avoiding the goto keyword1m 33s
-
(Locked)
Chapter challenge: Interpreting commands2m 26s
-
(Locked)
Chapter solution: Interpreting commands3m 55s
-
-
-
-
-
-
-
-