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.
Authenticating numeric input - C Tutorial
From the course: Secure Coding in C (2019)
Authenticating numeric input
- [Instructor] I'm not a fan of the scanf function. It's a good learning tool, but not something to use in a secure program. So in this code, the scanf function at line eight asks for integer input and that result is output right away. And I'll lie about my age. And it works. Now I'm going to run the program again but I'm going to supply text as input. And really I don't know where that answer is coming from, but it's not correct. Here's an example of the scanf function but used with floating point input. And I'll type in something desirable, and there you go. But now I'm going to run the program again and supply text input. And you see the text input was interpreted as zero, which is incorrect, zero was not input. There's something you can try with floating point input on some systems, which is to type nan for not a number. Now, on this system it interprets nan as zero, but on some computers, nan is a real number and…
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)
-
-
-