统计字符个数
#include <stdio.h> int main() { char c; int count=0; while((c=getchar())!='\n') { count++; } printf("\n"); printf("There are %d characters.\n", count); return 0; }
用for循环的处理办法
#include <stdio.h> int main() { char c; int i; for(i=0; (c=getchar())!='\n';i++) putchar(c+4); printf("\n"); printf("There are %d characters.\n", i); return 0; }
统计数字字符个数
#include <stdio.h> int main() { char c; int n=0; printf("Input a sentence: "); while((c=getchar())!='\n') { if(c>='0'&&c<='9') n++; } printf("There are %d number characters.\n", n); return 0; }