From the course: Secure Coding in C
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Minding string functions - C Tutorial
From the course: Secure Coding in C
Minding string functions
- [Instructor] The thing that makes a string in C, as well as many programming languages, is the null character. It terminates the string, marking the final character, which is an output. The null character is ASCII code zero, represented in C as the escape character, \0. String literals in C are created with an automatically appended null character. Strings you spin up yourself must be terminated with the null character. You code the null character, the compiler won't check it for you. And if you omit the null character, the string's end is undetermined, which leads to an overflow, an unsafe condition. Many of the C libraries string functions rely upon and maintain the null character when manipulating strings. Still, other functions may not set the null character, nor do the functions watch for overflows. In this code, the strncpy function copies characters, four of them, from string source to string dest. String…
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.