When working in C, we can use the ctype.h standard library set of functions to check the value of a char type variable.
We have access to several useful checks:
isalnum()checks if a character is alphanumericisalpha()checks if a character is alphabeticiscntrl()checks if a character is a control characterisdigit()checks if a character is a digitisgraph()checks if a character is a printable ASCII character (but not a space)islower()checks if a character is lowercaseisprint()checks if a character is a printable ASCII characterispunct()checks if a character is a punctuation character (a printable char, not a space, not alphanumeric)isspace()checks if a character is a whitespace character (see more later)isupper()checks if a character is uppercaseisxdigit()checks if a character is an hexadecimal digit (0-F)
I mentioned that isspace() checks if a character is a whitespace character. What is a whitespace character?
- Horizontal tab (HT),
'\t', character 9 of the ASCII table - Vertical tab (VT),
'\v', character 11 of the ASCII table - Form Feed (FF),
'\f', character 12 of the ASCII table - Carriage Return (CR),
'\r', character 13 of the ASCII table - Space,
' ', character 32 of the ASCII table - New line,
'\n'
Lessons in this unit:
| 0: | Introduction |
| 1: | Input and output |
| 2: | Variable scope |
| 3: | Static variables |
| 4: | Global variables |
| 5: | Type definitions |
| 6: | Enumerations |
| 7: | Structures |
| 8: | Command line parameters |
| 9: | Header files |
| 10: | The preprocessor |
| 11: | NULL values |
| 12: | Boolean values |
| 13: | Nesting functions |
| 14: | Conversion specifiers |
| 15: | Using quotes |
| 16: | String length |
| 17: | Returning strings |
| 18: | Array length |
| 19: | Looping through arrays |
| 20: | ▶︎ Checking character values |
| 21: | Printing percentage signs |
| 22: | Troubleshooting: Implicit function declarations |