From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: String I/O and manipulation

Solution: String I/O and manipulation - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Solution: String I/O and manipulation

(upbeat music) - [Instructor] For my solution I declared the two string buffers and the string literal at lines six, seven, and eight. Array name is set to 32 characters, which includes room for the null character and buffer, the target string ,is large enough to hold both the name array's text and the literal string last. It has more than enough room, which is fine. The while loop at line 17 fetches input. Variable a is first initialized at line 14. The loop repeats as long as the character fetched by the getchar function and stored in variable ch doesn't equal the new line. Within the loop the character fetch is stored in the name array at the element represented by variable a. Then there variable is incremented. Line 21 checks to see when the buffer gets full or reaches the 31st element. Remember that the first element is zero. If so, the loops breaks. Line 24 is very important. It caps the string input with the null character. Once the name string is collected the next part of the…

Contents