24-输入字符串判断字母数字空格其他数目

来源:互联网 发布:查看oracle数据库oid 编辑:程序博客网 时间:2024/05/21 16:53
#include <stdio.h>#include <conio.h>/*输入一段character,判断其中字母空格数字其他字符各有多少个?*/main(){//定义4个变量,分别用来保存字母、空格、数字、其他的个数int letter=0,space=0,digit=0,other=0;char c;//提示printf("please input a character:\n"); //接收用户输入的值    getchar()方法, while((c=getchar())!='\n'){//判断累加if(c>='a'&&c<='z'||c>='A'&&c<='Z'){letter++;}else if(c==' '){space++;}else if(c>='0'&&c<='9'){digit++;}else{other++;}}//输出最后的结果 printf("all in all:letters:%d,spaces:%d,digits:%d,others:%d",letter,space,digit,other);}




getchar();

从stdio流中读字符,相当于getc(stdin),它从标准输入里读取下一个字符

0 0
原创粉丝点击