I am trying to figure out how to check if a character is equal to white-space in C. I know that tabs are '\t'
and newlines are '\n'
, but I want to be able to check for just a regular normal space (from the space-bar) inside of an if
statement.
Does anybody know what is the character for this?
When parsing code, the C compiler ignores white-space characters unless you use them as separators or as components of character constants or string literals. Use white-space characters to make a program more readable. Note that the compiler also treats comments as white space.
When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area on a page. For example, the common whitespace symbol U+0020 SPACE (also ASCII 32) represents a blank space punctuation character in text, used as a word divider in Western scripts.
C isspace() The isspace() function checks whether a character is a white-space character or not. If an argument (character) passed to the isspace() function is a white-space character, it returns non-zero integer. If not, it returns 0.
Syntax. Commands are composed of sequences of spaces, tab stops and linefeeds. All other characters are ignored and thus can be used for comments. For example, tab-space-space-space performs arithmetic addition of the top two elements on the stack.
There is no particular symbol for whitespace. It is actually a set of few characters which are:
' ' space '\t' horizontal tab '\n' newline '\v' vertical tab '\f' form feed '\r' carriage return
Use isspace
standard library function from ctype.h
if you want to check for any of these white-spaces.
For just a space, use ' '
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With