Need Help C++ RLE Algorithim

  • Comp Sci
  • Thread starter CSteiner
  • Start date
  • #1
31
0

Homework Statement


[/B]
See this link for the given assignment.

http://eilat.sci.brooklyn.cuny.edu/cis1_5/HW5i_C.pdf [Broken]

note: on the last page the output aa4bcdd0cc1 is actually supposed to be aa3bcdd1cc1c.

Homework Equations



I have no idea why my encoder function doesn't work. No matter how I try to do it (I've tried strings, arrays - everything), the function copies the input exactly instead of encoding it. I followed the given pseudo code, and it had no problems for the decoder, but I must be doing something wrong for the encoder. Any advice would be appreciated

The Attempt at a Solution


[/B]
See the attached source code.
 

Attachments

Last edited by a moderator:

Answers and Replies

  • #2
You didn't attach the header file you are using.
Declare your function prototypes outside of main.
Why are you creating an ifstream object, not defining it, and then passing it to your encoder function?
Instead of having both ifstream and ofstream, check out fstream.
Your repeats variable should be an int, because it is a number, not a character.
Things are getting kind of weird with your previousbyte and byte definitions. Consider using a char array or a different standard template container.


No matter how I try to do it (I've tried strings, arrays - everything), the function copies the input exactly instead of encoding it. I followed the given pseudo code, and it had no problems for the decoder, but I must be doing something wrong for the encoder. Any advice would be appreciated
This either means your encoding function is wrong, or that the inequality to encode is not being met. Try changing the inequality to != and see if it works. If it does, then something is wrong with the way you are obtaining the bytes. If it still does not work then its your encoding algorithm.
 
  • #3
31
0
1. Whoops, it's attached now.
2.will do.
3. He kept on stressing that streams had to be passed by reference, so I thought he was implying it was necessary to pass streams in this assignment, and I didn't really think about it.
4. I'll play with that, thanks.
5. I had it as an integer initially, but classmate mentioned that he had success declaring it as a character, and I thought that might have been what was wrong. Turns out it didn't make a difference, but I forgot to change it back.
6. I've tried those, but it didn't help.

thanks for your tips, I'll implement them and see what happens.
 

Attachments

Related Threads on Need Help C++ RLE Algorithim

  • Last Post
Replies
11
Views
660
Top