×

Isalnum() function in C

Introduction:

The isalnum () is a function used in C programming language. This function checks the passing number or argument is an alphanumeric number or not.

The alphanumeric number consists of the alphabet (a-z or A-Z) and a numeric value (0-9). This function uses <ctype.h> header file in the program.

 The isalnum() function has zero value when the passed argument is not an alphabet or number. If the passed argument is alphanumeric, the function returns non-zero values.

For example, If we passed the alphabet 'a', then the isalnum() function returns non-zero values. Similarly, if we gave the numeric number '9', this function also returns the non-zero value. But when we passed neither an alphabet nor a numeric value, like '@', then this function returns zero.

Syntax of the isalnum() function in C language:

Syntax means the order or arrangement in the program. The syntax is also known as the function prototype. Every function has a syntax value. The syntax of the isalnum () function is:

int isalnum (int ch)

The isalnum() function checks whether the arguments are alphanumeric or non-alphanumeric. Here ch is taken as an argument or character.

Parameters of the isalnum() function in C language:

The main parameter of the isalnum() function is ch. Ch represents the given argument. Ch is checking whether the given value is alphanumeric or not an alphanumeric value.

Returns Value of the isalnum() function in C language:

The isalnum() function returns zero if the given number is not an alphanumeric value. The function returns a non-zero value if the given argument is an alphanumeric number. The alphanumeric numbers are 0 to 9, a to z and A to Z. The non alphanumeric values are @, #, %, $, etc.

Header file of the isalnum() function in C language :

Every program contains some header files. For the run of any program, you must need a header file. Without a header file, you can't run any programs. So, we must produce the header file in every program. It is a file with an extension.

The isalnum() function checks whether the given argument is alphanumeric or non-alphanumeric. The primary use of the header file is to propagate the declaration of code files.The header file of the isalnum() function in the C language is <ctype.h>.

It writes in the program as #include <ctype.h>.

Example 1

Here we given a example of the isalnum() function using C language:

//header file initialize

#include <stdio.h> 
#include <ctype.h> 
//main code of this program 
int main() 
{ 
char c;
 //print the result 
printf(“Enter a character : ”);
 scanf(“%c”, &c); 
if (isalnum(c) == 0) 
//print the result
printf (“The character is not an alphanumeric %c”,c); 
else 
printf (“The character is an alphanumeric %c”,c); 
//end the program 
return 0; 
}

 Output: We compile and run the above program. The result of this above program is:

 Enter a character: h 
The character is an alphanumeric h 
Enter a character: @ 
The character is not an alphanumeric @
 Enter a character: 3 
The character is an alphanumeric 3 

To better understand, we give another example of the isalnum() function.

Example 2

Here we given a example of the isalnum() function using C language:

//header file initialize

#include <stdio.h> 
#include <ctype.h> 
//main code of this program
int main() 
{ 
char value1 = ‘P’; 
char value2 = ‘5’; 
char value3 = ‘#’; 
if (isalnum(value1));
printf(“The character is an alphanumeric \n”); 
else
printf(“The character is not an alphanumeric \n”);
if (isalnum(value2)); 
printf(“The character is an alphanumeric \n”); 
else 
printf(“The character is not an alphanumeric \n”); 
if (isalnum(value3)); 
printf(“The character is an alphanumeric \n”);
else 
printf(“The character is not an alphanumeric \n”); 
//end the program
 return 0;
} 

Output: We compile and run the above program. The result of this above program is:

The character is an alphanumeric 
The character is an alphanumeric 
The character is not an alphanumeric 

In the above two programs, we have used the isalnum () function; by the programs, we briefly discussed how to write any C language program using the isalnum () function. The isalnum () function uses to check whether the given character is alphanumeric or not.

We use <ctype.h> header file in this program. The two programs' output depends on whether the input value is alphanumeric or non-alphanumeric. We also share the result of the above two programs.


Related Topics

Derived Data Types in C

A variable in a program occupies some space in the computer's memory where some value is stored. Each variable in C has an associated data type. A value to be...

4 minutes read.

Floyd’s triangle in C

Floyd’s triangle in C Floyd’s triangle is named after a person Robert Floyd. It is a right-angled triangle that is of natural numbers starting from 1 and consecutively selects the upcoming...

4 minutes read.

For Loop in C Programming Examples

The Syntax of the For Loop for (initialization statement; termination condition; modifying (increment/ decrement) statement) {       /* main body of the For loop */     } In for loop, the initialization command...

6 minutes read.

Inline Function in C

Inline Function in C A normal function will become an inline function when the function prototype of that function is prepended with the keyword "inline". Inline functions are the function where...

4 minutes read.

Const vs Volatile in C

Introduction Qualifiers are nothing but keywords which are used to modify the properties of a variable. Const and Volatile keywords are qualifiers in C. The Const qualifier is applied to the...

4 minutes read.

C Language Environment Setup

To compile C program, we must have GCC compiler installed on our machine. In this C tutorial, all the examples are compiled and tested using GCC compiler. Although we can...

3 minutes read.

GCD program of two numbers in C

GCD stands for Greatest Common Divisor, which is also known as Highest Common Factor, which can be abbreviated as HCF. Mathematically it can be defined as any two positive integers...

3 minutes read.

Call by Value and Call by Reference in C

Call by reference and call by value are two different ways of passing arguments to a function in C programming language. Call by reference means that the called function is...

4 minutes read.

Range of int in C

In this session we know about the rage of the int in C language with the suitable examples and the programs. Firstly, we can learn the range of int: The int is...

3 minutes read.

Union Program in C

 How should a union be defined?  In C programming, a Union is a method used to organize different data types into groups in the same way that Structures are used. We...

4 minutes read.

Decimal to Binary in C

What is a decimal number? A decimal number is a number represented in the decimal number system. This system of binary conversion uses base 10 to represent numbers, i.e. the digits...

3 minutes read.

Flow Chart of For loop in C

This is a flowchart that represents the process of executing the for loop in the C programming language. Generally, as we know there are three main components of for loop:1. The...

3 minutes read.

Beep() function in C

Introduction: Beep is a function which is used in C programming language. The beep function uses to make a beep sound. In the C language, when we want to generate...

3 minutes read.

Associativity of Operators in C

What is an Associativity operator? Two operators with equal priority are connected by employing their association when they are present in an expression. There are two different types of associativity: left to rightright...

4 minutes read.

C Program to find the Roots of a Quadratic Equation

What is Quadratic Equation: Equations of degree 2 in polynomial form are called quadratic equations. A, B, and C are the coefficient variables in the equation, which is written as ax2...

3 minutes read.

C Program to find the size of a File

Before knowing about the Program, you need to understand what the size of a file is. After that, you should know how it is going to work with the given...

4 minutes read.

What is required in each C Program?

Each C program must require one function, i.e., main() function. It is because when we execute the C program, C compiler looks for the main() function, and from here only...

5 minutes read.

Banker’s Algorithm in C

Introduction Before doing a "s-state" check to look for potential activities and deciding if allocation should be allowed to continue, the banker's algorithm, a resource allocation and deadlock avoidance algorithm, tests...

5 minutes read.

C program to Store Information of Students Using Structure

What is the Structure in C? User-defined data types include structures. Structures aid your ability to combine things of various categories into a single group. Like arrays, it operates similarly. A...

3 minutes read.

Prime Number Program in C using for Loop

In this article, we will know about the procedure of checking whether a natural number inputted by the user is a prime number or non-prime number. Definition of the prime number A...

3 minutes read.