|

楼主 |
发表于 2021-11-18 18:09:56
|
显示全部楼层
问题更新一下,修改完代码之后输入的字符出来了,
但是blank函数不起作用了。
代码如下:
- /*********************
- 编写一个用来统计输入的各个数字,空白符(空格、制表符、换行符)以及所有其他字符出现
- 次数的程序,分别存放在变量num[10],blank,others里面并打印出来。
- **********************/
- #include<stdio.h>
- #include<conio.h>
- int main(void)
- {
- int blank1(int blank);
- int blank=0;
- int blank2;
- int others1(int others);
- int others=0;
- int others2;
- others2=others1(others);
- blank2=blank1(blank);
- printf("空白符有%d个.\n",blank2);
- printf("其余字符有%d个.\n",others2);
-
- printf("\n\n");
- // system("pause");
- return 0;
- }
-
- int blank1(int blank) //负责空格符的函数
- {
- int blank3=0;
- int c;
-
- while((c=getchar())!=EOF)
- {
- if(c==' ' || c=='\t' || c=='\n')
- blank3++;
- }
- return blank3;
- }
- int others1(int others) //负责其他字符的函数
- {
- int others3=0;
- int c;
- while((c=getchar())!=EOF)
- {
- if(c>=33 && c<=47 || c>=58 && c<=126)
- {
- others3++;
- }
- }
- return others3;
- }
- /*
- int main(void)
- {
- int num[10]={0};
- int i,c;
- while((c=getchar())!=EOF)
- {
- if(c>='0'&&c<='9')
- {
- i=c-'0';
- num[i]++;
- }
- }
- for(i=0;i<10;i++)
- {
- printf("数字%d有%d个.\n",i,num[i]);
- }
- printf("\n\n");
- return 0;
- }
- */
复制代码 |
|