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: Reading commands - C Tutorial
From the course: Complete Guide to C Programming Foundations
Chapter solution: Reading commands
(uplifting music) - [Narrator] For my solution, I'm going to need a constant and two variables. Constant integer size sets the buffer size. Integer X is used as an offset, buffer input is where text input is stored. Within the while loop, I need to initialize the offset to zero. This statement appears before the prompt, so the offset is initialized each time a command is input. The first task is to fetch input. Input is stored in the input buffer. The maximum size is constant size, which includes the null character. STDIN is the standard input device. The next step is to convert the new line to a null character, which strips the new line from the string. For this task, I'll use a while loop. Loop until the character in the input buffer is the null character terminating the input string. Brace. Check for and convert the new line when it's found. When the new line is found, it's converted to the null character, and the loop stops. But as long as I'm looping through the string, I can use…
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
-
-
-
-
-