Your Ad Here

Wednesday, January 23, 2008

Run Length Encoding

/* C Program For The Implementation Of RUN LENGTH ENCODING */

#include< stdio.h>
#include< conio.h>
#include< string.h>
void main()
{
int i,j,cnt,l,count[50]={0};
char str[50];
clrscr();
printf("Enter the string: ");
scanf("%s",str);
printf("\n\tOriginal String is: %s",str);
printf("\n\n\tEncoded String is: ");
l = strlen(str);
for(i=0;i< l;i*=1)
{
j = 0;
count[i] = 1;
do
{
j++;
if(str[i+j] == str[i])
count[i]++;
}while(str[i+j]==str[i]);
if(count[i]==1)
printf("%c",str[i++]);
else
{
printf("$%d%c",count[i],str[i]);
i += count[i];
}
}
getch();
}
/************************* OUTPUT ************************
Enter the string: sleepzzzzzzzzzzzzzzzzzzz

Original String is: sleepzzzzzzzzzzzzzzzzzzz

Encoded String is: sl$2ep$19z */

12 comments:

Anonymous said...

Hi there.
I'm a B.Tech grad in India.
I'd been stuck with a couple of logical bugs and refering your code gave me peace of mind at last. Thanks a lot.

gok said...

hi dude ...
thanks a lot
was helpful

Anonymous said...

Hey!! thnx a lott!! :)

Anonymous said...

hi dude....thanks dude its was so helpful for me ...and i want to know how to write a code for zero run lenth encoding....

example:
from
-2,3,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0
to
(0,-2);(0,3);(0,1);(0,1);(0,1);(3,1);(15,0);(1,1);(0,0)

in brackets first value represent number of preceding zeros.last (0,0) means from that all are zeros.
i hope i will get a help for this .....
thanks.....:)

Anonymous said...

hi dude ....
ur code is impressive....
and i need a code for
converting
-2,3,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0
into
(0,-2);(0,3);(0,1);(0,1);(0,1);(3,1);(15,0);(1,1);(0,0)
in brackets first value represent number of preceding zeros before that number.
last (0,0) represent from that all are zeros....
hope i will get a code for this in c....
thanks.....

Das said...

hi dude ....
ur code is impressive....
and i need a code for
converting
-2,3,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0
into
(0,-2);(0,3);(0,1);(0,1);(0,1);(3,1);(15,0);(1,1);(0,0)
in brackets first value represent number of preceding zeros before that number.
last (0,0) represent from that all are zeros....
hope i will get a code for this in c....
thanks.....

Ds said...

hi dude ....
ur code is impressive....
and i need a code for
converting
-2,3,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0
into
(0,-2);(0,3);(0,1);(0,1);(0,1);(3,1);(15,0);(1,1);(0,0)
in brackets first value represent number of preceding zeros before that number.
last (0,0) represent from that all are zeros....
hope i will get a code for this in c....
thanks.....

yamini said...

Hi could you help me how to implement RSA algorithm in contiki OS.

Naresh Palle said...

how can we decode a encoded string ? I want code for decoding a encoded string also. Please provide source code for both...

Anonymous said...

please provide source code for decoding a encoded string...

Piu said...

hey hi..
i would like to say thanks..
ur code was so helpful for me..
thnks!!!!!!!!!

ujjwal said...

heyyy thankuu
bacha liya tune...

Your Ad Here