码迷,mamicode.com
首页 > 其他好文 > 详细

统计一个给定字符串中指定的字符出现的次数

时间:2015-01-04 23:08:06      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

统计一个给定字符串中指定的字符出现的次数

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	char source[80],dest[5];
	int len_s,len_d,*count;
	int temp,i,j;
	while(1)
	{
		gets(dest);
		gets(source);	
		if (strcmp(dest,"#")==0)
			break;
		else
		{
			len_s=strlen(source);
			len_d=strlen(dest);
			count=(int *)malloc(sizeof(int)*len_d);
			
			for(i=0;i<len_d;i++)
			{
				temp=0;
				j=0;
				while(j!=len_s)
				{
					if(dest[i]==source[j])
					{
						temp=temp+1;
						j++;
					}
					else
						j++;
				}
				count[i]=temp;			
			}
			for(i=0;i<len_d;i++)
				printf("%c %d\n",dest[i],count[i]);
		}			
	}
		return 0;		
	
}


统计一个给定字符串中指定的字符出现的次数

标签:

原文地址:http://blog.csdn.net/jxlijunhao/article/details/42402907

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!