×

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

Bit Fields in C

The size of a structure in C is specified in bits. The primary goal of it is to use memory efficiently, once we understand that a bit's value must fall...

3 minutes read.

Types of Function in C

A function is a piece of code that accomplish a certain operation for a specific task. There are two types of functions in C: System-defined function (Library Function)User-defined function 1. System defined Function...

8 minutes read.

How to delete a file in C

A file is a group of data kept on a secondary device, such as a hard disc. It is typically utilized as a real-world application with a lot of data. These...

3 minutes read.

C program to compare the two strings

C program to compare the two strings Strings can be compared either by using the string function or without using string function. First, we will look at how we can compare the strings with...

4 minutes read.

Errors in C

Errors in C Errors are nothing but problems or faults that pretty much occur in all the programming languages. Errors make the behavior of the program seem abnormal, and even the...

4 minutes read.

Nested loop in C

Definition of Nested Loop A nested loop is generally used when we want to run a loop statement inside another loop statement. This kind of loop is also known as a...

3 minutes read.

Command line arguments in C

Command line arguments in C The arguments that are generally passed from the line of command are referred to as command line arguments. These command line arguments are always handled by...

3 minutes read.

What is 2s Complement in C?

The complement of 2s in C is generated from the 1s in C. As we know, the 1s complement of a binary number is generated by converting bit 1 to...

4 minutes read.

Attributes in C

Attributes are one of modern C++ key features. It is the process by which initiator can add more information to the language instead of introducing new keywords for every attribute....

4 minutes read.

Types of Array in C

What is an Array? One value can be stored in a variable at once. How many variables will you need if you have 100 values? Well, the answer isn't 100. It...

14 minutes read.

SJF Scheduling Program in C

The SJF (shortest job first) or the shortest job next is the programming scheduling in the C. It is one of the CPU scheduling programming. The SJF is defined as...

4 minutes read.

Difference between rand() and srand() function in C

What is the rand()?The rand() means random function. This function is used in C. It generates random numbers in the range of 0 to the RAND_MAX. Suppose we generate a...

3 minutes read.

Difference between while and for loop in C

While Loop The syntax that can be used for the ‘while’ loop in the C programming language is mentioned below: while (test expression or termination condition)  {   // the main body of the...

6 minutes read.

Array to function in C

Array to function in C We can create functions that receive an array as an argument. To pass an array into a function, we need to write the name of the...

4 minutes read.

Armstrong Number in C

The Armstrong number is defined as the sum of each of its digits to the power of the number base for the each given number with any given number base....

3 minutes read.

Exponential() in C

Introduction: In C language, there are available many types of functions. The exponential() function is one of them. It is a mathematical function. This article describes using the pow() property to...

3 minutes read.

Static function in C

The functions in the C programming language are by default global. This means the programmer can easily access the function which is outside from the file where it was initially...

3 minutes read.

C Math Library

C Math Library The <math.h> header defines various mathematical functions and one macro. Many functions are available in this library to take double as an argument and then return double as...

4 minutes read.

Ceil function in C

Introduction In the C Programming Language, the ceil function is a library function which is used to obtain the ceil value, i.e., it returns the smallest integer that is greater than...

4 minutes read.

How to create a binary file in C?

Creating a binary file in C language is very simple, requiring only some specific functions to be implemented. There are also other binary modes: read, and write, which will be...

7 minutes read.