count.c

来自「unix环境下实现的cmm语言编译器」· C语言 代码 · 共 41 行

C
41
字号
/*count.c: 统计各个数字、空白及其它字符的次数*/int puts(char *);int printf(char *fmt, int);int getchar();int main(void){	int c, i, nwhite, nother;	int ndigit[10];		nwhite = nother = 0;	i = 0;	while (i < 10) {		ndigit[i] = 0;		i = i + 1;	}		while ((c = getchar()) != -1) {		if (c >= '0') 			if (c <= '9') {				ndigit[c-'0'] = ndigit[c-'0'] + 1;				continue;			}		if (c == ' ')			nwhite = nwhite + 1;		else if (c == '\n')			nwhite = nwhite + 1;		else if (c == '\t')			nwhite = nwhite + 1;		else			nother = nother + 1;	}	puts("digits =");	i = 0;	while (i < 10) {		printf(" %d", ndigit[i]);		i = i + 1;	}	printf(",white space = %d", nwhite);	printf(",other = %d\n",nother);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?