From the course: Secure Coding in C

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Authenticating numeric input

Authenticating numeric input - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

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…

Contents