isalnum() function of ctype.h in C

In this article, we are going to learn about the use isalnum() function of ctype.h header file in C language and use it to check various conditions.
Submitted by Manu Jemini, on April 04, 2018

We can use a simple function to check a character if it’s alphanumeric or not. The Function is called isalnum( param a), which accepts a single parameter which defines a character.

There can be numerous cases when we can use this function like checking for the characters in the password or username. A lot of websites have checks on emails, usernames, passwords etc.

The isalnum() function returns true if the character is alpha numeric and false if character is not alpha numeric. This can be useful if you want to check for sql injections.

This function is from the ctype.h file which needs to be included in the program.

ctype.h - isalnum() function Example in C



#include <stdio.h>
#include <ctype.h>
 
int main()
{
	// Defining the type of variables and initializing them
	char a='A';
	char b='@';
 
	// condition to prove that the value a is character
	If ( isalnum(a) == 1 )
	{
		printf("%c is a character \n\n", a);
	}
 
	// condition to prove that the value b is not a character
	If ( isalnum(b)== 0 )
	{
		printf("%c is not a character \n", b);
	}
 
	return 0;
}
 

Output

ctype.h - isalnum()  in c language



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.