From the course: Secure Coding in C
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Working with string literals - C Tutorial
From the course: Secure Coding in C
Working with string literals
- [Instructor] Here you see a string literal. It's text in double quotes, which can appear within a specific function, or it can be defined on its own for multiple uses. The string literal is assigned to the pointer prompt, which references the strings address in memory. This method of declaring a string literal is common. 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. It's best to use this string without modification, which can lead to trouble in other functions elsewhere in the code. So one solution is to make the string a constant. As a constant, the string can't be modified, which is okay for a string literal. The best solution, however, is to use a ray notation to reference such a string literal. You could make this declaration a constant as well, though the big difference is that the string is accessible elsewhere within your code, just in case you plan on doing something with it. To…
Contents
-
-
-
-
-
-
Allocating strings3m 25s
-
(Locked)
Avoiding bad string assignment1m 33s
-
(Locked)
Working with string literals2m 17s
-
(Locked)
Minding string functions3m 21s
-
(Locked)
Storing passwords and codes1m 39s
-
(Locked)
Clearing data after use1m 52s
-
(Locked)
Challenge: The secret code52s
-
(Locked)
Solution: The secret code3m 14s
-
-
-