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

  • Comp Sci
  • Thread starter CSteiner
  • Start date
  • Tags
    C++
In summary, the conversation discusses a problem with an encoding function for an assignment. The person is having trouble with the function copying the input instead of encoding it. Suggestions are made to check the inequality and to use different standard template containers. The person also mentions trying different stream objects and changing the data type of a variable without success. They plan to implement the suggestions and see if it helps.
  • #1
CSteiner
31
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

  • main.pdf
    20.8 KB · Views: 200
Last edited by a moderator:
Physics news on Phys.org
  • #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.
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.
 
  • #3
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

  • filecheck.pdf
    10.3 KB · Views: 219

Related to Need Help with C++ RLE Algorithm Homework | Troubleshooting Encoder Function

1. What is a C++ RLE algorithm?

A C++ RLE (Run-Length Encoding) algorithm is a data compression technique that reduces the size of a file by replacing repeated occurrences of the same data with a count and a single value. This helps to reduce the overall file size and make data transfer more efficient.

2. How does the C++ RLE algorithm work?

The C++ RLE algorithm works by scanning through a file and identifying repeated data. It then replaces the repeated data with a count and the single value. For example, if there are 5 consecutive "A" characters, the algorithm would replace them with "5A". This process helps to reduce the size of the file without losing any data.

3. What are the benefits of using a C++ RLE algorithm?

The main benefit of using a C++ RLE algorithm is that it can significantly reduce the size of a file, making data transfer more efficient. It is also a relatively simple and fast algorithm, making it suitable for use in real-time applications. Additionally, it can be used for both compressing and decompressing data.

4. Are there any limitations to the C++ RLE algorithm?

While the C++ RLE algorithm is effective at compressing data, it may not be as efficient as other compression techniques for certain types of data. For example, if a file contains a lot of random or non-repeating data, the algorithm may not be able to reduce the file size significantly. Additionally, the algorithm may not work well with highly compressed or already compressed files.

5. How can I implement a C++ RLE algorithm?

C++ RLE algorithms can be implemented in several ways, including using loops, arrays, and functions. One possible implementation is to read the file character by character and use counters to keep track of repeated data. The algorithm can then write the compressed data to a new file or overwrite the original file with the compressed data. There are also libraries and built-in functions in C++ that can be used to implement the RLE algorithm.

Similar threads

  • Engineering and Comp Sci Homework Help
2
Replies
43
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
5K
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
965
  • Engineering and Comp Sci Homework Help
Replies
15
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top