Previous Page
Next Page

isspace

Ascertains whether a given character produces space

#include <ctype.h>
int isspace ( int c  );

The function isspace( ) tests whether its character argument produces whitespace rather than a glyph when printedsuch 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.

See Also

The C99 function isblank( ), which returns true for the space and horizontal tab characters; the corresponding C99 functions for wide characters, iswspace( ) and iswblank( ); isalnum( ), isalpha( ), iscntrl( ), isdigit( ), isgraph( ), islower( ), isprint( ), ispunct( ), isxdigit( )


Previous Page
Next Page