DIGIT-ARC read-only archive · snapshot: July 23, 2026

RLE Encoding And Decoding using C..plz help.

21 posts · originally from https://geek.digit.in/community/threads/rle-encoding-and-decoding-using-c-plz-help.77647/

G
garv84 Original post #1
Jan 7, 2008 at 9:15 PM
Run length Encoding And Decoding

Example input: 123334455555AAA
Output for above input: 1\12\13\34\25\5A\3
QwertyManiac
Jan 7, 2008 at 11:25 PM
[edited as requested]
G
garv84 #3
Jan 8, 2008 at 3:42 PM
thats great bro.
M
Jan 8, 2008 at 4:33 PM
How about him giving your exams?
QwertyManiac
Jan 8, 2008 at 7:25 PM
Yeh, decoding is a piece of cake thats why. Try making something up and post it here if it doesn't work out. We'll help from there on. :)
QwertyManiac
Jan 8, 2008 at 8:17 PM
Whoa, people pay for getting their homeworks done? Am rich then! $$$$-)
G
garv84 #11
Jan 8, 2008 at 8:34 PM
Yeh, decoding is a piece of cake thats why. Try making something up and post it here if it doesn't work out. We'll help from there on. :)

ok bro..i'll try it up.
QwertyManiac
Jan 8, 2008 at 8:38 PM
Yeah try and post the problem you face along with what you did here.
G
garv84 #13
Jan 10, 2008 at 10:11 PM
plz tell me something..

say for ex : 1\125

all thses are characters.we are to print 1 125 tyms.how can we conver characters 125 into integar..??
ayush_chh
ayush_chh #14
Jan 11, 2008 at 11:04 AM
i am not getting this question, can anyone help me understand it?
QwertyManiac
Jan 11, 2008 at 4:40 PM
plz tell me something..

say for ex : 1\125

all thses are characters.we are to print 1 125 tyms.how can we conver characters 125 into integar..??
Use the atoi() function.

@ayush_chh - Run-Length Encoding is used to compress files in which a particular character is repeated several times in succession. Like say we have a file with the content:
Code:
LOOOOOOOOOOOOOOOOOOOOL

Total size: 22 Bytes
Thus using RLE compression technique, we can shorten it as:
Code:
L[B]O[/B][B]\20[/B]L

Comment: [B]O\20[/B] means O repeated 20 times. A decoder would look for the \ and the value after it and while expanding it, it'd print it that many times to get the output back in the actual form.

Total size: 6 Bytes
G
garv84 #16
Jan 11, 2008 at 7:32 PM
ya.got it.thanx QM..
QwertyManiac
Jan 11, 2008 at 8:38 PM
Great, so your solution is ready? :)
QwertyManiac
Jan 11, 2008 at 10:10 PM
Scalability would mean basically some kind of increase. Maybe you can add an option of including more than one file into the program for compression in one go and that would make it scalable.

Optimizing the program for more power at less CPU cost would also mean the same in certain cases.

Modularity would mean dividing the program into sub-programs (read as: functions). So make a function for encoding, decoding, 255 chop, and so on. Just split them so that if there is a new function to be added, it can make use of certain feature of this entire RLE exclusively.

Basically speaking, divide your program into sub programs. One function for decode, another for encode and so on. And collectively call them in main() to do a task thus accomplishing 'modularity'.
G
garv84 #19
Jan 11, 2008 at 10:16 PM
But i have implemented the encoding and the decoding in two different programs.will it be possible to call them as seperate functions in the main() method of a single program ..? or you mean to say calling a func encode() from main() in one and the other from the other prgrm..?

and hw to find the performance..do i need to calculate the complexity..?
QwertyManiac
Jan 11, 2008 at 10:20 PM
Two programs is fine too. But you can make it more easier by combining it into one can't you? You can detect the type of input file and perform the necessary execution (Encode or Decode) appropriately? Thats just my idea. But having 2 different programs is fine too, in modularity terms.

You can try increasing performance by modifying certain parts of your program. Its your style dependent. A small example (Unrelated to RLE perhaps) would be to replace that if-else ladder with a more optimized switch-case block. Things like that.
ayush_chh
ayush_chh #21
Jan 15, 2008 at 9:26 PM
thank you for explaining me the stuff.....:)