Common Linux C functions-character Testing

Source: Internet
Author: User
Tags printable characters uppercase character
Common Linux C functions-character testing-general Linux technology-Linux programming and kernel information. For more information, see the following section. Isalnum (test whether the character is English or a number)
Related functions: isalpha, isdigit, islower, and isupper

Header file # include

Defines the int isalnum (int c) function)

Function Description checks whether parameter c is an English letter or Arabic number. In Standard c, it is equivalent to using "isalpha (c) | isdigit (c)" for testing.

Returns TRUE if parameter c is a letter or number; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* Find the characters in the str string that are English letters or numbers */
# Include <ctype. h>
Main ()
{
Char str [] = "123c @ # FDsP [e ?";
Int I;
For (I = 0; str! = 0; I ++)
If (isalnum (str) printf ("% c is an alphanumeric character \ n", str );
}

Run 1 is an apphabetic character
2 is an apphabetic character
3 is an apphabetic character
C is an apphabetic character
F is an apphabetic character
D is an apphabetic character
S is an apphabetic character
P is an apphabetic character
E is an apphabetic character

 




Isalpha (test whether the character is an English letter)
Related functions: isalnum, islower, isupper

Header file # include

Defines the int isalpha (int c) function)

Function Description checks whether the parameter c is an English letter. In Standard c, it is equivalent to using "isupper (c) | islower (c)" for testing.

Returns TRUE if parameter c is an English letter; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* Find the characters in the str string that are English letters */
# Include
Main ()
{
Char str [] = "123c @ # FDsP [e ?";
Int I;
For (I = 0; str! = 0; I ++)
If (isalpha (str) printf ("% c is an alphanumeric character \ n", str );
}

Execute c is an apphabetic character
F is an apphabetic character
D is an apphabetic character
S is an apphabetic character
P is an apphabetic character
E is an apphabetic character

 




Isascii (test whether the character is an ASCII character)
Iscntrl

Header file # include

Defines the int isascii (int c) function );

Function Description checks whether the parameter c is an ASCII character, that is, whether the range of c is between 0 and 127.

Returns TRUE if the parameter c is an ASCII character; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* determine whether int I has an ASCII character mapped */
# Include
Main ()
{
Int I;
For (I = 125; I <130; I ++)
If (isascii (I ))
Printf ("% d is an ascii character: % c \ n", I, I );
Else
Printf ("% d is not an ascii character \ n", I );
}

Run 125 is an ascii character :}
126 is an ascii character :~
127 is an ascii character:
128 is not an ascii character
129 is not an ascii character

 




Iscntrl (test whether the character is an ASCII control character)
Isascii

Header file # include

Defines the int iscntrl (int c) function );

Function Description checks whether the parameter c is an ASCII control code, that is, whether the range of c is between 0 and 30.

If the return value is an ASCII control code, TRUE is returned. Otherwise, NULL (0) is returned ).

This is a macro definition, not a real function.

 




Isdigit (test whether the character is Arabic numerals)
Isxdigit

Header file # include

Defines the int isdigit (int c) function)

Function Description: Check whether the value of parameter c is 0 to 9.

If the return value is an Arabic number, TRUE is returned. Otherwise, NULL (0) is returned ).

This is a macro definition, not a real function.

Example/* Find the characters in the str string that are Arabic numerals */
# Include
Main ()
{
Char str [] = "123 @ # FDsP [e? ";
Int I;
For (I = 0; str! = 0; I ++)
If (isdigit (str) printf ("% c is an digit character \ n", str );
}

Execute 1 is an digit character
2 is an digit character
3 is an digit character

 




Isgraphis (test whether the character is printable)
Isprint

Header file # include

Defines the int isgraph (int c) function)

Function Description checks whether parameter c is printable. If the ASCII code mapped to c is printable, TRUE is returned if it is not a space character.

Returns TRUE if parameter c is printable; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* determine which of the str strings are printable characters */
# Include
Main ()
{
Char str [] = "a5 @;";
Int I;
For (I = 0; str! = 0; I ++)
If (isgraph (str) printf ("str [% d] is printable character: % d \ n", I, str );
}

Run str [0] is printable character:
Str [1] is printable character: 5
Str [3] is printable character :@
Str [4] is printable character :;

 




Islower (test whether the character is a lowercase letter)
Isalpha, isupper

Header file # include

Int islower (int c)

Function Description checks whether parameter c is a lowercase English letter.

If the return value is a lowercase English letter, TRUE is returned. Otherwise, NULL (0) is returned ).

This is a macro definition, not a real function.

Example # include
Main ()
{
Char str [] = "123 @ # FDsP [e? ";
Int I;
For (I = 0; str! = 0; I ++)
If (islower (str) printf ("% c is a lower-case character \ n", str );
}

Execute c is a lower-case character
S is a lower-case character
E is a lower-case character

 




Isprint (test character is (no is printable)
Isgraph

Header file # include

Defines the int isprint (int c) function );

Function Description checks whether parameter c is printable. If the ASCII code mapped to c is printable and contains space characters, TRUE is returned.

Returns TRUE if parameter c is printable; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* determine which of the str strings contain printable characters */
# Include
Main ()
{
Char str [] = "a5 @;";
Int I;
For (I = 0; str! = 0; I ++)
If (isprint (str) printf ("str [% d] is printable character: % d \ n", I, str );
}

Run str [0] is printable character:
Str [1] is printable character: 5
Str [2] is printable character:
Str [3] is printable character :@
Str [4] is printable character :;

 




Isspace (test whether the character is a space character)
Isgraph

Header file # include

Defines the int isspace (int c) function)

Function Description checks whether parameter c is a space character, that is, whether it is a space (''), a positioning character ('\ t'), or a CR (' \ R '), line feed ('\ n'), vertical positioning character (' \ V'), or flip ('\ F.

Returns TRUE if parameter c is a space character; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* find the space characters contained in the string str [] and display the ASCII code of the space characters */
# Include
Main ()
{
Char str = "123c @ # FD \ tsP [e? \ N ";
Int I;
For (I = 0; str! = 0; I ++)
If (isspace (str ))
Printf ("str [% d] is a white-space character: % d \ n", I, str );
}

Run str [4] is a white-space character: 32
Str [7] is a white-space character: 32
Str [10] is a white-space character: 9/* \ t */
Str [16] is a white-space character: 10/* \ t */

 




Ispunct (test whether the character is a punctuation or special symbol)
Related functions: isspace, isdigit, and isalpha

Header file # inlude

Int ispunct (int c)

Function Description checks whether parameter c is a punctuation or special symbol. TRUE indicates that parameter c is a non-space, non-digit, and non-English letter.

Return Value v if the parameter c is a punctuation or special symbol, TRUE is returned; otherwise, NULL (0) is returned ).

This is a macro definition, not a real function.

Example/* List punctuation marks or special characters in string str */
# Include
Main ()
{
Char str [] = "123c @ # FDsP [e? ";
Int I;
For (I = 0; str! = 0; I ++)
If (ispunct (str) printf ("% c \ n", str );
}

Run v
@#[?

 




Isupper (test whether the character is an uppercase English letter)
Related functions: isalpha and islower

Header file # include

Defines the int isupper (int c) function)

Function Description checks whether parameter c is an uppercase English letter.

Returns TRUE if parameter c is an uppercase English letter; otherwise, returns NULL (0 ).

This is a macro definition, not a real function.

Example/* Find the characters in str that are uppercase letters */
# Include
Main ()
{
Char str [] = "123c @ # FDsP [e? ";
Int I;
For (I = 0; str! = 0; I ++)
If (isupper (str) printf ("% c is an uppercase character \ n", str );
}

Execute F is an uppercase character
D is an uppercase character
P is an uppercase character

 




Isxdigit (test whether the character is a hexadecimal number)
Isalnum, isdigit

Header file # include

Defines the int isxdigit (int c) function)

Function Description checks whether the parameter c is a hexadecimal number. If c is one of the following, TRUE is returned. Hexadecimal number: 0123456789 ABCDEF.

If the return value is a hexadecimal number, TRUE is returned. Otherwise, NULL (0) is returned ).

This is a macro definition, not a real function.

Example/* Find the character string str is a hexadecimal number */
# Include
Main ()
{
Char str [] = "123c @ # FDsP [e? ";
Int I;
For (I = 0; str! = 0; I ++)
If (isxdigit (str) printf ("% c is a hexadecimal digits \ n", str );
}

Execute 1 is a hexadecimal digits
2 is a hexadecimal digits
3 is a hexadecimal digits
C is a hexadecimal digits
F is a hexadecimal digits
D is a hexadecimal digits
E is a hexadecimal digits
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.