统计一个给定字符串中指定的字符出现的次数
#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])" j++;="" }="" else="" count[i]="temp;" for(i="0;i<len_d;i++)" printf("%c="" %d\n",dest[i],count[i]);="" return="" 0;="" <="" pre=""><br>
<br> </len_d;i++)></stdlib.h></string.h></stdio.h>
本文提供了一段使用C语言实现的代码,用于统计给定字符串中指定字符出现的次数。通过使用预定义的函数和库,如`strlen`, `strcmp`, 和`malloc`,代码高效地实现了这一功能。

1806

被折叠的 条评论
为什么被折叠?



