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

alphabet string is called without integer.


Example: How to check string is alphabet or not in C++

Run it Now
#include<iostream>
#include<cstring>
using namespace std;

int main() {

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

    cout << "Enter  String value :";
    cin.getline(str, 100);

    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) {
        cout << "\nString is Alphabet :" << str;
    } else {
        cout << "\nString is not Alphabet :" << str;
    }

    return 0;
}

Output:

Enter  String value :Xiith
String is Alphabet :Xiith