How to check if a word is alphabetic in C

1 Answer

0 votes
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>

bool isAlphabetic(const char *word) {
    if (strlen(word) == 0) return 0;
    
    while (*word) {
        if (!isalpha(*word)) {
            return false; // Non-alphabetic character found
        }
        word++;
    }
    
    return true; // All characters are alphabetic
}

int main() {
    const char* word = ",c$programming.";

    if (isAlphabetic(word)) {
        printf("\"%s\" is alphabetic.\n", word);
    } else {
        printf("\"%s\" is not alphabetic.\n", word);
    }

    return 0;
}


    
/*
run:

",c$programming." is not alphabetic.

*/

 



answered Nov 2, 2025 by avibootz
edited Nov 2, 2025 by avibootz
...