C Program to check string is alphanumeric or not


In this program, You will learn how to check string is alphanumeric or not in c.


Some list of alphanumeric string: xiith123, john34, amit23, abc_98

Example: How to check string is alphanumeric or not in c.

#include<stdio.h>
#include<string.h>

int main() {

   char str[100];

   printf("Enter a string:");
   scanf("%[^\n]%*c", str); 

   int i = 0, k = 0, d = 0, p;

   i = strlen(str);

   for (int j = 0; j < i; j++) {
       p = str[j];
       if (p >= 97 && p <= 122)
           k++;
       else if (p >= 65 && p <= 90)
           k++;
       else if (p == 32)
           k++;
       else if (p >= 48 && p <= 57)
           d++;
   }

   if (k > 0 && d > 0) {
       printf("String is AlphaNumeric :%s", str);
   } else {
       printf("String is Not AlphaNumeric :%s", str);
   }

   return 0;
}

Output:

Enter a string:Xiith34 com
String is AlphaNumeric :Xiith34 com