Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is isxdigit in C?

Talha Ashar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The isxdigit function in C checks whether a character is a hexadecimal digit. Hexadecimal digits include the numbers 090-9, uppercase letters AFA-F, and lowercase letters afa-f.

To use the isxdigit function, you will need to include the <ctype.h> library in the program, as shown below:

#include <ctype.h>

The prototype of the isxdigit function is shown below:

int isxdigit(int c);

Parameters

The isxdigit function takes a single mandatory parameter, i.e., an integer that represents the character you want to check.

Note: In the C language, characters are treated as integer values.

Return Value

If the argument passed to the isxdigit function is a valid hexadecimal character, then the function returns a non-zero integer; otherwise, it returns 00.

Example

The code below shows how the isxdigit function works in C:

#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
// initializing string
char str[] = "ae2k3F9J";
// extracting characters
for(int i = 0; i < strlen(str); i++)
{
// hexadecimal check
if(isxdigit(str[i]))
{
printf("\'%c\' is a hexadecimal digit.\n", str[i]);
}
else
{
printf("\'%c\' is not a hexadecimal digit.\n", str[i]);
}
}
return 0;
}

Explanation

First, the code initializes a character array. A for-loop iterates over the length of this array and extracts each character.

Each extracted character is then provided as an argument to the isxdigit function on line 15.

The isxdigit function proceeds to check if the character is a valid hexadecimal digit and outputs the result accordingly.

RELATED TAGS

c

CONTRIBUTOR

Talha Ashar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring