How to check if character is letter in C

1 Answer

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

int main() {
    char s[] = "c programming";
    if (isalpha(s[0])) {
        printf("yes\n");
    } else {
        printf("no\n");
    }
    if (isalpha(s[1])) {
        printf("yes\n");
    } else {
        printf("no\n");
    }

    char ch = 'a';
    if (isalpha(ch)) {
        printf("yes\n");
    } else {
        printf("no\n");
    }
    
    printf("%s", isalpha('z') ? "yes" : "no");

    return 0;
}



/*
run:

no
yes
yes

*/

 



answered Jan 2, 2025 by avibootz

Related questions

1 answer 144 views
1 answer 162 views
1 answer 174 views
1 answer 161 views
...