The use of IsDigit () function and Isxdigit () function in C language _c language

Source: Internet
Author: User

C language IsDigit () function: To determine whether a character is an Arabic numeral
header file:

#include <ctype.h>

To define a function:

int isdigit (int c);

Function Description: Check whether the parameter C is Arabic numerals 0 to 9.

Return value: Returns true if parameter C is Arabic, otherwise null (0).

Additional description: This is a macro definition, not a true function.

Example: Find the characters in the STR string that are Arabic numerals.

#include <ctype.h>
Main () {
 char str[] = "123@ #FDsP [E?";
 int i;
 for (i = 0; Str[i]!= 0; i++)
  if (IsDigit (str[i)))
   printf ("%c be an digit character\n", str[i));

Execution results:

1 is a digit character
2 is a digit character
3 is a digit character

C language Isxdigit () function: To determine whether a character is a 16 binary number

Header file:

#include <ctype.h>

To define a function:

int isxdigit (int c);

Function Description: Check whether the parameter C is a 16 binary number, as long as C is one of the following conditions to detect success.

16 binary number: 0123456789ABCDEF.

Return value: If parameter C is a 16-digit number, it returns a non-0, otherwise it returns 0.

Additional description: This is a macro definition, not a true function.

Example: finds characters in string str that are hexadecimal digits.

#include <ctype.h>
Main () {
 char str[] = "123c@ #FDsP [E?";
 int i;
 for (i = 0; Str[i]!= 0; i++)
  if (Isxdigit (str[i)))
   printf ("%c be a hexadecimal digits\n", str[i]);

Execution results:

1 is a hexadecimal digits
2 are a hexadecimal digits
3 is a hexadecimal digits
c is a hexadecimal DIGITS
   f is a hexadecimal digits
D are 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.