isalnum() - Character Function

How is "isalnum()" used in C++?

Explanation

isalnum() is used to check whether the given argument is alphanumeric character (integer or uppercase/lowercase alphabets). This function returns zero when the argument does not have any of them.

Syntax:


int isalnum ( int c );

Example :



#include <iostream.h>
#include <ctype.h>
int main()
{
char a;
cout << "Enter a alphanumeric character::\n" << endl;
cin >> a;
if(isalnum(a))
{
cout << "Alpha-numeric character";
}
else
{
cout << "Not a Alpha-numeric";
}
return 0;
}

Result :

Enter a alphanumeric character::
3
Alpha-numeric character

In the above example, this function is used to check if the entered number is alphanumeric. It checks if the ASCII value passed in has a character equivalent to a number of letter.

C++ Tutorial


Ask Questions

Ask Question