From the course: Secure Coding in C

Unlock the full course today

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

Solution: Enter the combination

Solution: Enter the combination - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Solution: Enter the combination

(upbeat music) - [Instructor] Here's my solution for the challenge, focusing on the get number function. First, ensure you've adequately set the input buffer size, which I do here at line nine, as a constant integer value, four. This size provides room for two digits, the new line character which must be accepted or it screws up the stream input, and then the null character at the end of the string. That's four characters total. Storage is allocated at line 13, and verified in case the null is returned. Line 20 obtains and verifies input, confirming that the input string is an empty or null. Line 28 verifies the input value. Then on line 37, it's confirmed that the input is within the range of zero to 99. With the proper input value obtained, the for loop at line 44 clears out the input buffer number, replacing its contents with null characters. This step adds security. Finally, at line 47, the input buffer is free.…

Contents