Thread: Huffman encoding issue. please helo!

  1. #1
    Registered User
    Join Date
    Dec 2012

    Huffman encoding issue. please helo!

    so im working with huffman encoding. i have a porgram that runs, but there are 2 problems im having.
    first (and more important): the program will run, but seg.faults when it occurs a punctuation followed by a new line character. it can handle the two by themselves, but it screws up when they are next to each other and i dont know why.

    second: i have a memory leak. there are two allocations i cant seem to free correctly.

    the code is here

    i can provide the other files if you would like, but it will have to be a mediafire link.
    thank you so much for even looking at my code. any bit helps

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    1. Your indentation needs work. Indentation - cpwiki

    2. This is a buffer overrun
    if ((compressed_array[i][1] > compressed_array[i+1][1])&&(compressed_array[i+1][1]!= 0))

    3. If you're getting segfaults, have you run it in gdb?
    The debugger will point you directly at a line of code containing an illegal memory reference.

    4. Have you run it under valgrind?
    valgrind can tell you about memory leaks AND tell you the line of code responsible for allocating that particular block.
    From that, it's usually enough to be able to figure out where to free it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Huffman encoding
    By sigur47 in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2012, 08:05 PM
  2. HUffman encoding(data compression)
    By jia in forum C++ Programming
    Replies: 4
    Last Post: 06-01-2010, 03:44 PM
  3. XML encoding issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-16-2008, 05:21 AM
  4. huffman encoding help
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 04-17-2002, 12:51 PM
  5. Huffman Encoding
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-29-2001, 02:31 PM