From the course: Secure Coding in C (2019)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Working with string literals - C Tutorial
From the course: Secure Coding in C (2019)
Working with string literals
- [Instructor] A string literal is text in double quotes. It can appear within a specific function, or be defined on its own for multiple uses. In this code, you see a common method for declaring a string literal. At line five the prompt pointer references the string, press any key. This method of declaring a string literal is common, and I use it, but it has a few quirks, one of which is that the pointer references memory in a different way than had you allocated it yourself. One solution is to make the string a constant, as shown in line five in this code. As a constant, the string can't be modified, which is okay for a string literal. Still, an allocation problem looms in the code. The best solution is to use array notation to reference the string literal, as shown here at line five. You could even make this declaration constant as well, though the big difference is that the string is accessible within your code, just…
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
-
-
-
-
-
-
(Locked)
Allocating strings2m 40s
-
(Locked)
Avoiding bad string assignment1m 28s
-
(Locked)
Working with string literals2m
-
(Locked)
Minding string functions3m 47s
-
(Locked)
Storing passwords and codes1m 15s
-
(Locked)
Clearing data after use1m 13s
-
(Locked)
Challenge: The secret code40s
-
(Locked)
Solution: The secret code1m 43s
-
(Locked)
-
-