Trouble implementing isalpha

后端 未结 1 1216
迷失自我
迷失自我 2021-01-26 04:12

I\'ve been working on the readability problem in CS50. The first step is to create a way to count only the alphabetical characters. It suggests to use the isalpha f

相关标签:
1条回答
  • 2021-01-26 04:24
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    int main(void)
    {
        const char* s = get_string ("Text: \n");
        int count = 0;
    
        while(*s) count += !!isalpha(*s++);
    
        printf ("%d\n", count );
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题