1原来char c;(c=getchar())!='\n可以用来输入一串字符。
#include <stdio.h>
int main(void) {
char c;
int letters = 0,space = 0,digit = 0,others = 0;
printf("please input some characters\n");
while((c = getchar())!='\n'){
if(c>='a'&&c<='z'||c>='A'&&c<='Z'){
letters++;
}
else if(c==' '){
space++;
}
else if(c<='9'&&c>='0'){
digit++;
}
else{
others++;
}
}
printf("letters is %

这篇博客涵盖了C++编程的基础知识,包括利用(c=getchar())!='
'读取字符串,寻找一千以内的完数,解析自由落体运动的物理问题,设计乒乓球比赛的逻辑,以及探讨如何在C语言中表示分数。通过这些实例,读者可以加深对C/C++编程及基础算法的理解。
最低0.47元/天 解锁文章
1295

被折叠的 条评论
为什么被折叠?



