我正在尝试编写一个计算字符串中多个元素的程序。其中第一个是字母。
该作业是CS50第2周问题集的一部分,因此包括库。
使用while条件,我能够对每个字符进行计数,但是一旦我添加了isalpha >>(它检查字符是否为字母数字),代码便停止工作。
我在做什么错?
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
string text = get_string("Text: ");
printf("%s, \n", text);
int letters = 0;
while (text[letters] !='\0')
{
if (isalnum(text[letters]))
{
letters++;
}
}
printf("%i \n", letters);
}
我正在尝试编写一个计算字符串中多个元素的程序。其中第一个是字母。作业是CS50第2周问题集的一部分,因此包含了库。 ...
这里显示了如何定义正确的循环