isblank


isblank

Ascertains whether a given character is a space or tab character

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

The function isblank( ) is a recent addition to the C character type functions. It returns a nonzero value (that is, TRue) if its character argument is either a space or a tab character. If not, the function returns 0 (false).

Example

This program trims trailing blank characters from the user's input:

 #define MAX_STRING 80 char raw_name[MAX_STRING]; int i; printf( "Enter your name, please: " ); fgets( raw_name, sizeof(raw_name), stdin ); /* Trim trailing blanks: */ i = ( strlen(raw_name) - 1 );   // Index the last character. while ( i >= 0 )                // Index must not go below first character. {   if (  raw_name[i] == '\n' )     raw_name[i] = '\0';         // Chomp off the newline character.   else if ( isblank( raw_name[i] ) )     raw_name[i] = '\0';         // Lop off trailing spaces and tabs.   else     break;                      // Real data found; stop truncating.   --i;                          // Count down. } 

See also the example for isprint( ) in this chapter.

See Also

The corresponding C99 function for wide characters, iswblank( ); isalnum( ), isalpha( ), iscntrl( ), isdigit( ), isgraph( ), islower( ), isprint( ), ispunct( ), isspace( ), isupper( ), isxdigit( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net