This is standard run length encoding algorithm.#include#include#include#include#define MAX_R_LEN 50char *encode(char *src){ int i=0,j=0,k,rLen; char count[MAX_R_LEN]; int len=strlen(src); char *dest=(char*)malloc(sizeof(char)*(2*len+1)); for(i=0;i1) { sprintf(count, "%d",rLen); for(k=0;*(count+k);k++,j++) { dest[j]=count[k]; } } } dest[j]='\0'; return dest; }int main(){ char str[]="AAABBBBBCDEHH"; printf("%s ", encode(str)); getch(); return 0;}
This is standard run length encoding algorithm.
ReplyDelete#include
#include
#include
#include
#define MAX_R_LEN 50
char *encode(char *src)
{
int i=0,j=0,k,rLen;
char count[MAX_R_LEN];
int len=strlen(src);
char *dest=(char*)malloc(sizeof(char)*(2*len+1));
for(i=0;i1)
{
sprintf(count, "%d",rLen);
for(k=0;*(count+k);k++,j++)
{
dest[j]=count[k];
}
}
}
dest[j]='\0';
return dest;
}
int main()
{
char str[]="AAABBBBBCDEHH";
printf("%s ", encode(str));
getch();
return 0;
}