Because the C compiler doesn't do much rigorous checking, it's up to you, the programmer, to properly manage strings. Always allocate enough storage for a string. Never forget the null character at the end of the string.
- [Narrator] As a C programmer you must be extremely … careful when dealing with strings … as the compiler doesn't check that the storage … is the proper size or that the null character is present. … Unlike other higher level languages the burden is … on you, the programmer, to check these conditions. … Fortunately I have only a few suggestions … plus some other tips on working with strings … to help avoid problems. … First, ensure that proper storage is allocated for a string. … For array notion properly set the buffer size. … That's the number of characters you plan … on putting into the string plus one … for the null character, and if you declare a string literal … you can just leave the brackets empty. … The compiler calculates the proper storage required. … If you're using a pointer to allocate string storage … ensure that the buffer size is large enough … to hold the string plus one for the null character. … This type of allocation makes more sense if … you've studied pointers and memory allocation. …
- 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.