0

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);
0

I tested a few ideas, and found the answer. Instead of doing if (isalpha(*txt)), I had to do if(isalpha(txt[i])).

You must log in to answer this question.

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