1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need Help C++ RLE Algorithim

  1. Nov 25, 2015 #1
    1. The problem statement, all variables and given/known data

    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.

    2. Relevant 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

    3. The attempt at a solution

    See the attached source code.
     

    Attached Files:

    Last edited by a moderator: May 7, 2017
  2. jcsd
  3. Nov 25, 2015 #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.


    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.
     
  4. Nov 25, 2015 #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.
     

    Attached Files:

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted