ADVERTISEMENT
ADVERTISEMENT

Home » C programs » ctype.h header file functions

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

ADVERTISEMENT


#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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.