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

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