C-language string processing-----compressed string

Source: Internet
Author: User

Soon to graduate, recently a period of time has been looking at some of the basics of C language. Plan to share some of the latest gains from today. Let's write a program about string compression today.

Simply put, a string such as "Aaaaabcccddde", written as "A5b1c3d3e1". The code is as follows

void Yasu (char *s)
{

 char *p;
 Char reschar[100];//holds the compressed string
 memset (reschar,null,sizeof (Reschar));//string assignment is null
 p=s;
 int count=1;
 int k=0;

 int Len=strlen (s);

 for (int i=0;i<=len-1;i++)
 {
  if (P[i+1]==p[i])
  {
   count++
  }
  else
  {
   //sprintf (Reschar+strlen (Reschar), "%c%d", p[i],count);
   if ((count>=10) && (count<100))
   {
    int d1=count%10;
    int d2= (COUNT/10)%10;
    reschar[k++]=d2+ ' 0 ';
    reschar[k++]=d1+ ' 0 ';
   }
   else
   {
    
   reschar[k++]=count+ ' 0 ';

   }

  Itoa (count,reschar[k++],10);

   Count=1
  }


 }
 printf ("%s\n", Reschar);

}


If you have any questions, please ask.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.