现在的位置: 首页 > 综合 > 正文

数组:统计字符数字空格其它

2014年03月04日 ⁄ 综合 ⁄ 共 413字 ⁄ 字号 评论关闭
#include "stdio.h"
int main() {
	int i,j,upp,low,dig,spa,oth;
	char text[3][80];

	upp=low=dig=spa=oth=0;

	for (i=0;i<3;i++) {
		printf("Please input line %d\n",i+1);
		gets(text[i]);
		for (j=0;j<80 && text[i][j]!='\0';j++) {
			if (text[i][j]>='A' && text[i][j]<='Z')
				upp++;
			else if (text[i][j]>='a' && text[i][j]<='z')
				low++;
			else if (text[i][j]>='0' && text[i][j]<='9')
				dig++;
			else if (text[i][j]==' ')
				spa++;
			else
				oth++;
		}
	}
	printf("\n %d %d %d %d %d\n",upp,low,dig,spa,oth);

}

抱歉!评论已关闭.