#include
int main ()
{
int var1 = 'd';
int var2 = '2';
int var3 = 't';
int var4 = '';
if (isalnum (var1))
{
printf ("var1 = |% c | la ky tu-son", var1);
}
else
{
printf ("var1 = |% c | is not sure", var1);
}
if (isalnum (var2))
{
printf ("var2 = |% c | la ky tu-son", var2);
}
else
{
printf ("var2 = |% c | is not sure", var2);
}
if (isalnum (var3))
{
printf ("var3 = |% c | la ky tu-son", var3);
}
else
{
printf ("var3 = |% c | is not sure", var3);
}
if (isalnum (var4))
{
printf ("var4 = |% c | la ky tu-son", var4);
}
else
{
printf ("var4 = |% c | is not sure", var4);
}
return (0);
}
Compiling and running the above C program will result:
Void function isalpha (int c) in Library C checks whether the transmitted character is a letter.
Below is the declaration for the isalpha () function in C:
int isalpha ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a non-zero value if c is a letter, otherwise the function returns 0.
For example
The following program C illustrates the usage of isalpha () function in C:
#include #include int main () { int var1 = 'd' ; int var2 = '2' ; int var3 = 't' ; int var4 = ' ' ; if ( isalpha ( var1 ) ) { printf ( "var1 = |%c| la mot chu cain" , var1 ); } else { printf ( "var1 = |%c| khong phai la mot chu cain" , var1 ); } if ( isalpha ( var2 ) ) { printf ( "var2 = |%c| la mot chu cain" , var2 ); } else { printf ( "var2 = |%c| khong phai la mot chu cain" , var2 ); } if ( isalpha ( var3 ) ) { printf ( "var3 = |%c| la mot chu cain" , var3 ); } else { printf ( "var3 = |%c| khong phai la mot chu cain" , var3 ); } if ( isalpha ( var4 ) ) { printf ( "var4 = |%c| la mot chu cain" , var4 ); } else { printf ( "var4 = |%c| khong phai la mot chu cain" , var4 ); } return ( 0 ); }
Compiling and running the above C program will result:
Function void iscntrl (int c) in Library C checks whether the transmitted character is a control character
According to the standard ASCII character set, ASCII encoded control characters are 0x00 (NUL), 0x1f (US), and 0x7f (DEL). Some private implementations of specific platforms may define some additional control characters in the extended character set (on 0x7f).
Below is the declaration for the iscntrl () function in C:
int iscntrl ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a non-zero value if c is a control character. If not, the function returns 0.
For example
The following C program illustrates the usage of iscntrl () in C:
#include #include int main () { int i = 0 , j = 0 ; char str1 [] = "Hoc a lap trinh t hay nhat" ; char str2 [] = "tai n QTM" ; /* in chuoi cho toi khi gap ky tu a */ while ( ! iscntrl ( str1 [ i ]) ) { putchar ( str1 [ i ]); i ++; } /* in chuoi cho toi khi gap ky tu n */ while ( ! iscntrl ( str2 [ j ]) ) { putchar ( str2 [ j ]); j ++; } return ( 0 ); }
Compiling and running the above C program will result:
Void isdigit function (int c) in Library C checks whether the transmitted character is a decimal number.
Decimal digits include - 0 1 2 3 4 5 6 7 8 9.
Below is the declaration for the isdigit () function in C:
int isdigit ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a non-zero value if c is a digit. If not, the function returns 0.
For example
The following C program illustrates the usage of isdigit () function in C:
#include #include int main () { int var1 = 'h' ; int var2 = '2' ; if ( isdigit ( var1 ) ) { printf ( "var1 = |%c| la mot ky son" , var1 ); } else { printf ( "var1 = |%c| khong phai la mot ky son" , var1 ); } if ( isdigit ( var2 ) ) { printf ( "var2 = |%c| la mot ky son" , var2 ); } else { printf ( "var2 = |%c| khong phai la mot ky son" , var2 ); } return ( 0 ); }
Compiling and running the above C program will result:
The function void isgraph (int c) in Library C checks whether the transmitted character must be graphical with Locale given.
Graphic characters are a set of alphanumeric characters and punctuation characters
Here is the declaration for the function isgraph () in C:
int isgraph ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a non-zero value if c is a graphical character. If not, the function returns 0.
For example
The following program C illustrates the usage of the isgraph () function in C:
#include #include int main () { int var1 = '3' ; int var2 = 'm' ; int var3 = ' ' ; if ( isgraph ( var1 ) ) { printf ( "var1 = |%c| la co the in duocn" , var1 ); } else { printf ( "var1 = |%c| la khong the in duocn" , var1 ); } if ( isgraph ( var2 ) ) { printf ( "var2 = |%c| la co the in duocn" , var2 ); } else { printf ( "var2 = |%c| la khong the in duocn" , var2 ); } if ( isgraph ( var3 ) ) { printf ( "var3 = |%c| la co the in duocn" , var3 ); } else { printf ( "var3 = |%c| la khong the in duocn" , var3 ); } return ( 0 ); }
Compiling and running the above C program will result:
The int islower (int c) function in Library C checks whether the transmitted character is a lowercase letter.
Below is the declaration for the islower () function in C:
int islower ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a value other than 0 (true) if c is a lowercase letter. Otherwise the function returns 0 (false).
For example
The following program C illustrates the usage of islower () function in C:
#include #include int main () { int var1 = 'Q' ; int var2 = 'q' ; int var3 = '3' ; if ( islower ( var1 ) ) { printf ( "var1 = |%c| la mot ky tu chu thuongn" , var1 ); } else { printf ( "var1 = |%c| khong phai la mot ky tu chu thuongn" , var1 ); } if ( islower ( var2 ) ) { printf ( "var2 = |%c| la mot ky tu chu thuongn" , var2 ); } else { printf ( "var2 = |%c| khong phai la mot ky tu chu thuongn" , var2 ); } if ( islower ( var3 ) ) { printf ( "var3 = |%c| la mot ky tu chu thuongn" , var3 ); } else { printf ( "var3 = |%c| khong phai la mot ky tu chu thuongn" , var3 ); } return ( 0 ); }
Compiling and running the above C program will result:
The int isprint (int c) function in Library C checks whether the transmitted character can print. A printable character is a character that is not a control character.
Below is the declaration for the isprint () function in C:
int isprint ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a value other than 0 (true) if c is a printable character. Otherwise the function returns 0 (false).
For example
The following program C illustrates the usage of the isprint () function in C:
#include #include int main () { int var1 = 'k' ; int var2 = '8' ; int var3 = 't' ; int var4 = ' ' ; if ( isprint ( var1 ) ) { printf ( "var1 = |%c| co the in duocn" , var1 ); } else { printf ( "var1 = |%c| khong the in duocn" , var1 ); } if ( isprint ( var2 ) ) { printf ( "var2 = |%c| co the in duocn" , var2 ); } else { printf ( "var2 = |%c| khong the in duocn" , var2 ); } if ( isprint ( var3 ) ) { printf ( "var3 = |%c| co the in duocn" , var3 ); } else { printf ( "var3 = |%c| khong the in duocn" , var3 ); } if ( isprint ( var4 ) ) { printf ( "var4 = |%c| co the in duocn" , var4 ); } else { printf ( "var4 = |%c| khong the in duocn" , var4 ); } return ( 0 ); }
Compiling and running the above C program will result:
The int ispunct (int c) function in Library C checks whether the transmitted character is a char punctuation. Character punctuation is a collection of! "# $% & '() * +, -. /:; <=>? @ [] ^ _` {|} ~
Here is the declaration for the ispunct () function in C:
int ispunct ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a value other than 0 (true) if c is a punctuation character. Otherwise the function returns 0 (false).
For example
The following program C illustrates the use of the ispunct () function in C:
#include #include int main () { int var1 = 't' ; int var2 = '1' ; int var3 = '/' ; int var4 = ' ' ; if ( ispunct ( var1 ) ) { printf ( "var1 = |%c| la mot ky tu punctuationn" , var1 ); } else { printf ( "var1 = |%c| khong phai la mot ky tu punctuationn" , var1 ); } if ( ispunct ( var2 ) ) { printf ( "var2 = |%c| la mot ky tu punctuationn" , var2 ); } else { printf ( "var2 = |%c| khong phai la mot ky tu punctuationn" , var2 ); } if ( ispunct ( var3 ) ) { printf ( "var3 = |%c| la mot ky tu punctuationn" , var3 ); } else { printf ( "var3 = |%c| khong phai la mot ky tu punctuationn" , var3 ); } if ( ispunct ( var4 ) ) { printf ( "var4 = |%c| la mot ky tu punctuationn" , var4 ); } else { printf ( "var4 = |%c| khong phai la mot ky tu punctuationn" , var4 ); } return ( 0 ); }
Compiling and running the above C program will result:
The function int isspace (int c) in Library C checks whether the transmitted character is white-space.
Here are the whitespace characters in Library C:
' ' ( 0x20 ) kho ả ng tr ố ng ( SPC ) 't' ( 0x09 ) tab ngang ( TAB ) 'n' ( 0x0a ) newline ( d ò ng m ớ i ) - d ò ng m ớ i ( LF ) 'v' ( 0x0b ) tab doc ( VT ) 'f' ( 0x0c ) feed ( FF ) 'r' ( 0x0d ) carriage return ( CR )
Below is the declaration for the isspace () function in C:
int isspace ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a value other than 0 (true) if c is the whitespace character. Otherwise the function returns 0 (false).
For example
The following program C illustrates the usage of the isspace () function in C:
#include #include int main () { int var1 = 't' ; int var2 = '1' ; int var3 = ' ' ; if ( isspace ( var1 ) ) { printf ( "var1 = |%c| la mot khoang trangn" , var1 ); } else { printf ( "var1 = |%c| khong phai la mot khoang trangn" , var1 ); } if ( isspace ( var2 ) ) { printf ( "var2 = |%c| la mot khoang trangn" , var2 ); } else { printf ( "var2 = |%c| khong phai la mot khoang trangn" , var2 ); } if ( isspace ( var3 ) ) { printf ( "var3 = |%c| la mot khoang trangn" , var3 ); } else { printf ( "var3 = |%c| khong phai la mot khoang trangn" , var3 ); } return ( 0 ); }
Compiling and running the above C program will result:
The function int isupper (int c) in Library C checks whether the transmitted character is a capital letter.
Below is the declaration for the isupper () function in C:
int isupper ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a value other than 0 (true) if c is uppercase. Otherwise the function returns 0 (false).
For example
The following program C illustrates the usage of the isupper () function in C:
#include #include int main () { int var1 = 'M' ; int var2 = 'm' ; int var3 = '3' ; if ( isupper ( var1 ) ) { printf ( "var1 = |%c| la mot ky tu chu hoan" , var1 ); } else { printf ( "var1 = |%c| khong phai la mot ky tu chu hoan" , var1 ); } if ( isupper ( var2 ) ) { printf ( "var2 = |%c| la mot ky tu chu hoan" , var2 ); } else { printf ( "var2 = |%c| khong phai la mot ky tu chu hoan" , var2 ); } if ( isupper ( var3 ) ) { printf ( "var3 = |%c| la mot ky tu chu hoan" , var3 ); } else { printf ( "var3 = |%c| khong phai la mot ky tu chu hoan" , var3 ); } return ( 0 ); }
Compiling and running the above C program will result:
The function int isxdigit (int c) in Library C checks whether the transmitted character is a hexadecimal character (hexa character).
Below is the declaration for the isxdigit () function in C:
int isxdigit ( int c );
Parameters
c - This is the character to be checked.
Returns the value
This function returns a value other than 0 (true) if c is a hexadecimal character. Otherwise the function returns 0 (false).
For example
The following C program illustrates the usage of isxdigit () function in C:
#include #include int main () { char var1 [] = "tuts" ; char var2 [] = "0xE" ; if ( isxdigit ( var1 [ 0 ]) ) { printf ( "var1 = |%s| la mot ky tu hexan" , var1 ); } else { printf ( "var1 = |%s| khong phai la mot ky tu hexan" , var1 ); } if ( isxdigit ( var2 [ 0 ] )) { printf ( "var2 = |%s| la mot ky tu hexan" , var2 ); } else { printf ( "var2 = |%s| khong phai la mot ky tu hexan" , var2 ); } return ( 0 ); }
Compiling and running the above C program will result:
The library nge.h also contains two conversion functions that receive and return an int:
Int tolower (int c) - This function converts uppercase letters to lowercase
Int toupper (int c) - This function converts lowercase letters to uppercase
The int tolower function (int c) in Library C converts the given character to lowercase.
Here is the declaration for tolower () function in C:
int tolower ( int c );
Parameters
c - This is a character to be converted to lowercase.
Returns the value
This function returns a letter that is normally equivalent to c if that value exists, otherwise c will not change. The value is returned as an int value that can be implicitly cast to char.
For example
The following C program illustrates the use of tolower () function in C:
#include #include int main () { int i = 0 ; char c ; char str [] = "TUTORIALS POINT" ; while ( str [ i ] ) { putchar ( tolower ( str [ i ])); i ++; } return ( 0 ); }
Compile and run the above C program to see the results:
The int toupper function (int c) in Library C converts lowercase letters to uppercase.
Below is the declaration for the toupper () function in C:
int toupper ( int c );
Parameters
c - This is a character to be converted to uppercase.
Returns the value
This function returns a capital letter equivalent to c if that value exists, otherwise c will not change. The value is returned as an int value that can be implicitly cast to char.
For example
The following program C illustrates the usage of the toupper () function in C:
#include #include int main () { int i = 0 ; char c ; char str [] = "Tutorials Point" ; while ( str [ i ]) { putchar ( toupper ( str [ i ])); i ++; } return ( 0 ); }
Compile and run C program to see results:
This is a collection of all numbers {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Hexadecimal digitsThis is a set of {0 1 2 3 4 5 6 7 8 9 ABCDEF abcdef}
Lowercase lettersIs a collection of all lowercase {abcdefghijklmnopqrstu vwxyz}
Flower lettersIs a collection of all uppercase letters {ABCDEFGHIJKLMNOPQRSTU VWXYZ}
AlphabetIs a collection of all upper and lower case letters
Alphanumeric charactersIs a set of numbers, upper and lower case letters
Punctuation charactersIs a collection! "# $% & '() * +, -. /:; <=>? @ [] ^ _` {|} ~
Graphical charactersIs a set of alphanumeric characters and punctuation characters
Whitespace charactersA set of tabs, newline (new line), vertical tab, form feed, carriage return, and space
Printable charactersA set of alphanumeric characters, punctuation characters and whitespace characters
Control charactersIn ASCII, these characters have octal encoding from 000 to 037, and 177 (DEL)
Blank charactersThese characters include space and tab characters
Alphabetical charactersIs a collection of upper and lower case letters
According to Tutorialspoint
Last lesson: assert.h in C
Next article: errno.h in C