Skip to content

How to check a character value in C

Learn how to check a character value in C

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 alphanumeric
  • isalpha() checks if a character is alphabetic
  • iscntrl() checks if a character is a control character
  • isdigit() checks if a character is a digit
  • isgraph() checks if a character is a printable ASCII character (but not a space)
  • islower() checks if a character is lowercase
  • isprint() checks if a character is a printable ASCII character
  • ispunct() 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 uppercase
  • isxdigit() 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'
→ Download my free C Handbook!

THE VALLEY OF CODE

THE WEB DEVELOPER's MANUAL

You might be interested in those things I do:

  • Learn to code in THE VALLEY OF CODE, your your web development manual
  • Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
  • I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
  • Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
  • Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
  • Find me on X

Related posts that talk about clang: