Name
isspace
Synopsis
Ascertains whether a given character produces space
#include <ctype.h> intisspace( intc);
The function isspace()
tests whether its character argument produces whitespace rather than
a glyph when printed—such as a space, tabulator, newline, or the
like. If the argument is a whitespace character, isspace() returns a nonzero value (that
is, true); if not, the function
returns 0 (false).
Which characters fall into the whitespace class depends on the
current locale setting for the category LC_CTYPE, which you can query or change
using the setlocale() function.
In the default locale C, the
isspace() function returns
true for the characters in Table 17-3.
Table 17-3. Whitespace characters in the default locale, C
Character | ASCII name | Decimal value |
|---|---|---|
'\t’ | Horizontal tabulator | 9 |
'\n’ | Line feed | 10 |
'\v’ | Vertical tabulator | 11 |
'\f’ | Page feed | 12 |
'\r’ | Carriage return | 13 |
' ' | Space | 32 |
Example
char buffer[1024];
char *ptr = buffer;
while ( fgets( buffer, sizeof(buffer), stdin ) != NULL )
{
ptr = buffer;
while (isspace( *ptr )) // Skip over leading whitespace.
ptr++;
printf( "The line read: %s\n", ptr );
}See also the example for isprint() in this
chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access