About five days ago i posted here a piece of code that produced a segfault. After using the advices from some members the code worked but now its giving a segfault again for a different set of data. I cant understand why its working for one set and not for the other so i m reposting the code in case some of you can see other mistakes in it.
You didn't take the earlier advice to refactor this into smaller functions. This is a very large function with insane indentation. Of course it will have problems.
My advice: break it up into smaller chunks. The problem will be easier to track down.
Try keeping functions to no more than 20 lines and no more than 3 levels of indentation. What this does is reduce the Cyclomatic Complexity of a function. http://en.wikipedia.org/wiki/Cyclomatic_complexity
It would also help to use a cleaner coding style. Style and legibility really does matter.
Ok. I took PanGalactic's advice and for the past two days i've been trying to divide my code into smaller functions. It has actually been really helpful since it is a lot easier to debug it now. The next problem i have to deal with is the following: I need to make a function in order to retrieve the data for the algorithm. I this function i'm declaring an array of type "nodes" which is a structure of integer values. This array is necessary for some other functions in my code but when i try to compile the program i get errors saying the array was not declared or something like that. Is it possible to do this? If so can you give me any advice on how to?