Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - isxdigit()

C library function - isxdigit()

C Standard Library - <ctype.h> C Standard Library -

Description

C Library Function int isxdigit(int c) Checks whether the passed character is a hexadecimal digit.

int isxdigit(int c) The parameter c is a single character.

Hexadecimal is generally represented with the digits 0 to 9 and the letters A to F (or a~f), where A~F represent 10~15: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F.

Declaration

Here is the declaration of the isxdigit() function.



int isxdigit(int c);

Parameters

Return Value

If c is a hexadecimal digit, the function returns a nonzero integer value; otherwise it returns 0.

Example

The following example demonstrates the use of the isxdigit() function.

Example

#include

<

ctype.h

#include

<

stdio.h

int

main

(

)

{

char

c

= '

5

';

int

result

;

// Pass in a character

result

=

isxdigit

(

c

)

;

// result returns nonzero

printf

(

"

The result of passing %c to the isxdigit() function is: %d

"

,

c

,

isxdigit

(

c

)

)

;

printf

(

"

\

n

"

)

;

// Newline

c

= '

M

';

// Non-hexadecimal number as the argument

result

=

isxdigit

(

c

)

;

// result is 0

printf

(

"

The result of passing %c to the isxdigit() function is: %d

"

,

c

,

isxdigit

(

c

)

)

;

return

0

;

}

Let's compile and run the above program, which will produce the following result:



5 传入到 isxdigit() 函数结果为: 1

M 传入到 isxdigit() 函数结果为: 0

Find the characters in the string that are hexadecimal digits:

Example

#include

<

ctype.h

#include

<

stdio.h

int

main

(

)

{

char

str

[

]

=

"

123c@#run[oobe?

"

;

int

i

;

for

(

i

=

0

;

str

[

i

]

!='\

0

';

i

++

)

{

if

(

isxdigit

(

str

[

i

]

)

)

{

printf

(

"

%c is a hexadecimal number

\

n

"

,

str

[

i

]

)

;

}

}

}

Let's compile and run the above program, which will produce the following result:



1 是一个十六进制数

2 是一个十六进制数

3 是一个十六进制数

c 是一个十六进制数

b 是一个十六进制数

e 是一个十六进制数

C Standard Library - <ctype.h> C Standard Library -