C Program to check string is alphabet or not


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


Some list of alphabet string: xiith, john, amit, abc


Example: How to check string is alphabet or not in c

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

int main() {

   char str[100];
   int i = 0, k = 0, p;

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

   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++;
   }

   if (k == i) {
       printf("\nString is Alphabet :%s", str);
   } else {
       printf("\nString is not Alphabet :%s", str);
   }

   return 0;
}

Output:

Enter String value :Xiith
String is Alphabet :Xiith