北航计算机机试07字符串统计

从输入的字符串中,统计空格,回车,TAB出现的次数

#include <stdio.h>
#include <string.h>
int main(){
int space_count,enter_count,tab_count;
space_count = enter_count=tab_count=0;
char ch,buf[1024];//设置数组容量值为最大


////////////////////////////////////////
ch=getchar();
int i=0;
while(ch!='\\')  //以"\"作为输入标志
{
buf[i]=ch;
ch=getchar();
i++;
}
buf[i]='\0'; 
//////////////////////////////////////////利用while代替for 先取值,判断,主体,递增 
int length = strlen(buf);

////////////////////////////////
for(i=0;i<length;i++){
ch = buf[i];
if(ch == ' '){
space_count++;
}
else if(ch == '\n'){
enter_count++;
}
else if(ch == '\t'){
tab_count++;
}
}
/////////////////////////////////
printf("%d,%d,%d",space_count,enter_count,tab_count);
return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
阿里巴巴各部门年终奖开奖了,有人拿到了220w
真烦好烦真烦:拿命换钱呢,公司给你220万,肯定是因为你对公司的贡献大于220万,想想要多厉害多累才能达到
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务