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.
Reading input with fgets() - C Tutorial
From the course: Secure Coding in C (2019)
Reading input with fgets()
- [Instructor] The original C language string input function, gets, has been deprecated. It's still available, but using it is dangerous. And this code gets appears at line eight. Fetch input and store it in the named buffer. No limit is offered on input, so it definitely can overflow. And when you build normally, depending on the compiler, you would see a warning message. Here the warning doesn't show up, which I'm curious about. Yet when I go to Ubuntu Linux and I use the clang compiler with the -Wall switch, you see the warning in the output. The gets function is dangerous and should not be used. This warning may also appear in the compiled program. To run the program, yes, it works, but I would not recommend it. The proper replacement for the gets function is the fgets function shown here at line eight. It restricts input to the size of its second argument minus one for the terminating null character. And as a…
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)
Authenticating numeric input2m 54s
-
(Locked)
Converting strings to numbers2m 23s
-
(Locked)
Using int values instead of char2m 32s
-
(Locked)
Reading input with fgets()4m 7s
-
(Locked)
Filtering string input4m 14s
-
(Locked)
Challenge: Confirming input1m 2s
-
(Locked)
Solution: Confirming input1m 54s
-
(Locked)
-
-
-