将字符串中连续相同的字符表达成字符加个数的形式输出

来源:互联网 发布:zip linux 解压命令 编辑:程序博客网 时间:2024/05/18 01:18

例如 hello  输出hel2o; 

#include<stdio.h>
#include<string.h>
void spluscount(char *string)
{
  int n=strlen(string);
  char k;
  int s=0;
  int count=1;
  char outstring[32]={0};  //定义重新输出的数组
  for(int i =0; i <=n;)
  {
    k=string[i];        //   取一个字符
for(int j =i+1; j <= n;j++)  //判断后面有几个字母和所取字符相等
if(k==string[j])
{
  count++;
  i++;
}
else                   //如果不相等了,重新输入输出数组中等待最终输出
{
 if(count==1)
outstring[s]=k;
 else
 { 
 outstring[s]=k;
 count=count+'0';
 outstring[++s]=count;}
puts(outstring);
  s++;
  i++;
  count=1;
  break;
}
  
  
  }
  // puts(outstring);


}
 int main(void)
 {
  char a[]="asedseeesesees";
 // char b[10];
  spluscount(a);
 


 
 return 0;
 }


0 0