I'm trying to use isalpha, but for some reason it's not working and counting everything, including spaces and punctuation. I tried to use isupper||islower with the same results. Any ideas why this is happening or something else i can use instead. Thanks!

string txt = get_string ("Text: ");

    int length = 0;
    for (int i = 0; i < strlen(txt); i++)
        if (isalpha(*txt))
          length ++;
    printf("%i letter(s)\n", length);
  • Can you share your code?
    – azh412
    Aug 14, 2020 at 21:07

1 Answer 1


Without seeing how you're using it, there's no way to answer.

However, note that isalpha, isupper, islower, etc., can ONLY look at one character. If you pass it a string, like argv[1], it will result in a seg fault.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .