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

Run it Now
#include<stdio.h>
#include<string.h>

int main() {

   char str[100];

   printf("Enter a String :");
   fgets(str, 100, stdin);

   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("\nString is AlphaNumeric :%s", str);
   } else {
       printf("\nString is Not AlphaNumeric :%s", str);
   }

   return 0;
}

Output:

Enter a String :Hello y2
String is AlphaNumeric :Hello y2