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 an alphabet or not in C++.

#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 << "String is alphabet:" << str;
    } else {
        cout << "String is not alphabet:" << str;
    }

    return 0;
}

Output:

Enter string value:Welcome to Xiith
String is alphabet:Welcome to Xiith