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.
Examplechar 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 AlsoThe 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( ) |