From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Avoiding string problems - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Avoiding string problems
- [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. The number of…
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
-
Testing characters2m 34s
-
Working with character conversions2m 17s
-
Understanding strings in C3m 3s
-
Fetching string input3m 18s
-
Sending string output2m 46s
-
Reviewing printf() placeholders3m 8s
-
Using printf() placeholders3m 36s
-
Exploring string functions3m 29s
-
Manipulating strings3m 53s
-
Avoiding string problems2m 27s
-
Challenge: String I/O and manipulation1m 46s
-
Solution: String I/O and manipulation2m 16s
-
-
-
-
-