欢迎来到山村网

解析如何利用switch语句进行字符统计

2019-03-02 10:03:29浏览:109 来源:山村网   
核心摘要:#include stdio.hvoid cotTime();main(){cotTime();}void cotTime(){int c, i, nwhite, nother, ndigit[10];nwhite = nother = 0

#include <stdio.h>
void cotTime();
main()
{
cotTime();
}
void cotTime()
{
int c, i, nwhite, nother, ndigit[10];
nwhite = nother = 0;
for(i=0;i<10;i++)
{
ndigit[i] = 0;
}
while((c = getchar()) != EOF)
{
switch(c)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':

ndigit[c-'0'] += 1;
break;

case ' ': case '/t': case '/n':
nwhite++; break;

default:
nother++;
break;
}
}
printf("digits = ");
for(i=0;i<10;i++)
{
printf(" %d",ndigit[i]);
}
printf(", white space = %d, other = %d/n", nwhite, nother);
return 0;
}

(责任编辑:豆豆)
下一篇:

C#中将字符串转换为整型的三种解决方法总结

上一篇:

jquery对dom的操作常用方法整理

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com