黑马程序员技术交流社区

标题: 交流 [打印本页]

作者: 又欠又欠    时间: 2016-4-6 21:19
标题: 交流
2.输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。 #include<stdio.h> 
int letter,digit,space,others; void main() { 
 void count(char[]);  char text[80]; 
 printf("Please input string:\n");  gets(text); 
 printf("string:\n");  puts(text);  letter=0;  digit=0;  space=0;  others=0;  count(text); 
 printf("letter:%d,digit:%d,space:%d,others:%d\n",letter,digit,space,others); } 
void count(char str[]) { 
 int i; 
 for(i=0;str[i]!='\0';i++) 
  if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))    letter++; 
  else if(str[i]>='0'&&str[i]<='9')    digit++; 
  else if(str[i]==32)    space++;   else 
   others++; }




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2