Comp Sci Need Help with C++ RLE Algorithm Homework | Troubleshooting Encoder Function

  • Thread starter Thread starter CSteiner
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
The discussion revolves around troubleshooting a C++ Run-Length Encoding (RLE) algorithm, specifically focusing on an encoder function that fails to produce the expected output. The user reports that their function copies the input directly instead of encoding it, despite following the provided pseudo code. Suggestions include declaring function prototypes outside of the main function, using the correct data types for variables, and ensuring that streams are passed correctly. Additionally, modifying the inequality condition in the encoding logic may resolve the issue. The user plans to implement the feedback received to improve their encoder function.
CSteiner
Messages
31
Reaction score
0

Homework Statement


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

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

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:
Physics news on Phys.org
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.
CSteiner said:
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.
 
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

Similar threads

Replies
17
Views
5K
Replies
15
Views
2K
Replies
21
Views
3K
Replies
14
Views
5K
Back
Top