从键盘输入一串字符串,统计字符串中特定字符的个数(特定字符也需要从键盘输入),并输出个数。
#include “stdio.h”
#include “conio.h”
#include “string.h”
void main()
{ char s[100],ch;
int i,nch=0;
printf(“Input a string:”);
gets(s);
printf(“Input a searched character:”);
scanf(“%c”,&ch);
i=0;
while(s[i])
if(s[i++]==ch) nch++;
printf(“Number of \’%c\’ is %d\n”,ch,nch);
getch();
}
运行结果:
Input a string:For example!
Input a searched character:e
Number of ’e’ is 2
© 版权声明
部分文章来自网络,只做学习和交流使用,著作权归原作者所有,遵循 CC 4.0 BY-SA 版权协议。
THE END





![ps色相/饱和度使用教程——在[色相/饱和度]对话框中指定调整的颜色范围-伊丞小站(YLIMHS.COM)](https://www.ylimhs.com/wp-content/uploads/2020/05/20200504_5eb02afdd8bcc.png)



暂无评论内容