1、程序代码
#include <stdio.h>
#include<string.h>
void func(char *a)
{
char *p=a;
int cout=1;
while(*p)
{
if(*p==*(p+1))
{
cout++;
}
else
{
if(1!=cout)
{
printf("%d",cout);
}
printf("%c",*p);
cout=1;
}
p++;
}
putchar('\n');
}
int main(int argc, char *argv[])
{
char a[20]={0};
printf("请输入字符串:\n");
gets(a);//获取字符串,使用gets()输入函数会报警告,但是不影响结果。
printf("处理后的字符串为:\n");
func(a);//调用函数
return 0;
}
2、结果: