title: How to compress a string and replace duplicates with its count using C?
body: <p>I have a large string char myStr="AAAABBBCCCCCCDDDEFGHHIJJ".
  I shall pass this string to my string compressing function which should return me the string in below format myStr ="A4B3C6D3EFGH2IJ2"
  Also, the new string replacements should happen in the same passed string only. One cannot create a temp array.</p>
  
  <p>Below is my func and am not able to figure out the deletion of duplicates and replacing with its count in the same string.</p>
  
  <pre><code> #include&lt;stdio.h&gt;
   #include&lt;string.h&gt;
  
  
   char* StrCompress(char myStr[])
   {
  char *s = myStr;
  int len = strlen(myStr);
  char *in = myStr;
  int count =0;
  int i=0;
  
  
  while(*(s) != '\0')
  {
      if(*(s)==*(s+1))
      {
          count++;
  
          if(count == 1)
          {
              in = s;
          }
          s++;
  
      }
      else
      {
          //myStr[count-1]=count;
          memcpy(in+1,s+1,count);
          s=in;
          count =0;
  
      }
      i++;
  }
  
  return myStr;
  
  
  
  }
  
  int main(){
  
  char myStr[] ="AAAABBBCCCCCEEFGIIJJJKLMNNNNOOO";
  
  printf("Compressed String is : %s\n",StrCompress(&amp;myStr));
  
  return 0;
  
  }
  </code></pre>