How it works...
The user is asked to enter a number. A user-defined getdata() function is invoked and the value returned by the function is assigned to the numb variable, which in return is then displayed on the screen. The getdata function will keep asking for the digits of the number and will return the number when the Enter key is pressed.
Let's assume that the user wants to enter 20. Within the getdata function, the getchar_unlocked() function is invoked. So, on entering the first digit, 2 (of the number 20), it will be assigned to the cdigit variable, which is of the character data type. The ASCII value of 2 is 50, so the value 50 is actually assigned to the cdigit variable.
Before proceeding further, we ensure that the value entered ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access