C programming isblank ctype.h


In C programming the <ctype.h> isblank function check if the argument is blank or locale-specific set of character for which ‘isspace’ is true.In “C”(English) locale only the standard blank characters ‘ ‘(space) and ‘\t'(horizontal tab) returns true.The declaration of the function is given below.

int isblank(int c);

Parameters:
c -The character to be tested for blank.

Return type
int -Return non-zero value if the character is blank.

A code example is given below when the locale is set to “C”:default locale.

Code example

printf(“%d” , isblank(‘ ‘) );

printf(“\n%d” , isblank(‘\t’) );

printf(“\n%d” , isblank( 32 ) );

printf(“\n%d” , isblank( 34 ) );

Output in CB,

1
1
1
0

In the third line the argument passed is 32 and the return value is 1(true) since the corresponding character for the integer value 32 is the space character.




isblank behavior when the locale is not set to “C” locale

Suppose we set the locale to some other locale say to German locale by calling the function setlocale(LC_CTYPE , “deu_DEU.1252” ) (the string “deu_DEU.1252” is what changes the locale to German).Now let’s try passing the standard blank characters and see if the they are accepted as blank characters in German locale.Consider the code below.

Code example for Code::blocks user

setlocale(LC_CTYPE , “deu_DEU.1252”)(LC_CTYPE , “deu_DEU.1252”);

printf(“%d” , isblank(‘ ‘) );

printf(“\n%d” , isblank(‘\t’) );

Output in CB

1
1

Since the returned values are true it means they are accepted as blank character in German.


Related links

->C isspace

->C isgraph

->C isalnum ctype.h

->C iscntrl ctype.h