w3resource

C isalnum() function

C isalnum(int ch)

The isalnum() function is used to check whether the argument ch is a character of class alpha or digit in the current locale. The function is defined in the ctype.h header file.

Syntax:

int isalnum(int argument);

isalnum() Parameters:

Name Description Required /Optional
ch Argument ch represents a character. Required

isalnum() Return Value:

  • The isalnum() function returns non-zero if ch is an alphanumeric character; otherwiset returns 0.

Example-1: isalnum() function return value

#include <stdio.h>
#include <ctype.h>
int main()
{
    char ch;
    int result;
    ch = '8';
    result = isalnum(ch);
    printf("Return value is %d When %c is passed as an argemdent.", result, ch);
    ch = '$';
    result = isalnum(ch);
    printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);
    ch = '+';
    result = isalnum(ch);
    printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);
    ch = 'A';
    result = isalnum(ch);
    printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);  
	ch = '-';
    result = isalnum(ch);
    printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);   
    return 0;
}

Output:

Return value is 4 When 8 is passed as an argemdent.
Return value is 0 When $ is passed as an argemdent.
Return value is 0 When + is passed as an argemdent.
Return value is 1 When A is passed as an argemdent.
Return value is 0 When - is passed as an argemdent.

Example #2: Check whether a character is an alphanumeric or not!

#include <stdio.h>
#include <ctype.h>
int main()
{
    char ch;
    printf("Input a character: ");
    scanf("%c", &ch);
    printf("Check the said number is alphanumeric characte or not!");
	    if (isalnum(ch) == 0)
        printf("\n%c is not an alphanumeric character.", ch);
    else
        printf("\n%c is an alphanumeric character.", ch);
    return 0;
}

Output:

Input a character: J
Check the said number is alphanumeric characte or not!
J is an alphanumeric character.

C Programming Code Editor:

Previous C Programming: C type Home
Next C Programming: C isalpha()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming/ctype/c-isalnum.php