Programming Project
For this project you are to code two functions that accept C-string parameters.
bool allDigits(char str[])
This function accepts a C-string parameter (null-terminated char array) and return true if the C-string contains only digits. The function is to return false if the C-string contains any other character.
char *firstNonDigit(char str[])
This function accepts a C-string parameter and returns a pointer to the first non- digit that occurs in the string. If the string contains only digits, the function is to return the value null.
The main function for this project is to follow the indicated algorithm:
Repeat
Prompt for an int, read it into a Cstring
If the string contains any illegal (non-digit) characters
Print out an error message that contains the first non-digit of the input
Until a valid string (all digits) is entered
Convert the C-string to an int (the atoi function in the cstdlib library is
handy here)
Print out the int that was input, and also twice that value
You may find the cctype library, as discussed in Section 8.5 helpful in determining if a character is a digit. Alternatively, a digit is simply a character within the range ‘0' - ‘9'.