Join Dan Gookin for an in-depth discussion in this video Solution: String I/O and manipulation, part of C: Data Structures, Pointers, and File Systems.
(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 code, …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.