What's the escape sequence for blanks in C?

Viewed 79060

I'm writing a program to count blanks, tabs, and newlines. I remember what the escape sequence for tabs and newlines are, but what about blanks? \b? Or is that backspace?

5 Answers

Space is simply ' ', in hex it is stored as 20, which is the integer equivalent of 32. For example:

if (a == ' ')

Checks for integer 32. Likewise:

if (a == '\n')

Checks for integer 10 since \n is 0A in hex, which is the integer 10. Here are the rest of the most common escape sequences and their hex and integer counterparts:

code: │   name:                │Hex to integer:
──────│────────────────────────│──────────────
\n    │  # Newline             │  Hex 0A = 10
\t    │  # Horizontal Tab      │  Hex 09 = 9
\v    │  # Vertical Tab        │  Hex 0B = 11
\b    │  # Backspace           │  Hex 08 = 8
\r    │  # Carriage Return     │  Hex 0D = 13
\f    │  # Form feed           │  Hex 0C = 12
\a    │  # Audible Alert (bell)│  Hex 07 = 7
\\    │  # Backslash           │  Hex 5C = 92
\?    │  # Question mark       │  Hex 3F = 63
\'    │  # Single quote        │  Hex 27 = 39
\"    │  # Double quote        │  Hex 22 = 34
' '   │  # Space/Blank         │  Hex 20 = 32
Related