Huffman encoding issue. please helo!

This is a discussion on Huffman encoding issue. please helo! within the C Programming forums, part of the General Programming Boards category; so im working with huffman encoding. i have a porgram that runs, but there are 2 problems im having. first ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    3

    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
    https://gist.github.com/4430213




    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    1. Your indentation needs work.
    SourceForge.net: 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 07: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, 01:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21