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()



Share this Tutorial / Exercise on : Facebook and Twitter

C Programming: Tips of the Day

What's an object file in C?

An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)

A linker takes all these object files and combines them to form one executable (assuming that it can, i.e.: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)

Ref : https://bit.ly/3CbzF8M