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 - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Using single character I/O4m 4s
-
(Locked)
Testing characters2m 34s
-
(Locked)
Working with character conversions2m 17s
-
(Locked)
Understanding strings in C3m 3s
-
(Locked)
Fetching string input3m 18s
-
Sending string output2m 46s
-
(Locked)
Reviewing printf() placeholders3m 8s
-
(Locked)
Using printf() placeholders3m 36s
-
(Locked)
Exploring string functions3m 29s
-
(Locked)
Manipulating strings3m 53s
-
(Locked)
Avoiding string problems2m 27s
-
(Locked)
Challenge: String I/O and manipulation1m 46s
-
(Locked)
Solution: String I/O and manipulation2m 16s
-
-
-
-
-