| INeedAHero (31) | |||||||
|
I'm trying to multiply two arrays together, but it keeps creating a segment fault. No matter what I do I can't make it go away. My program compiles, but the result just says "segmentation fault" This is my main function:
This is my multiplication function: (and MAX2 just equals 39)
And this is the add(...) function, in case you guys need it:
The error definitely lies in the multiplication function. But the multiplication was working correctly earlier - problems only started coming up when I converted it into object-based code. Anyone see where a segment fault could be coming from? Thanks in advance! | |||||||
|
Last edited on
|
|||||||
| INeedAHero (31) | |||
|
Anyone have any idea? I looked at this:
And thought that resultmult.MAX - i would be 40 when addzero is equal to zero....which is the case, and that would cause the segmentation fault. But no, fixing that error does not erase the segmentation fault. It seems that no matter what I do it won't go away! Any ideas? | |||
|
|
|||
| INeedAHero (31) | |||||
|
Hey guys, I found something a little strange. I decided to comment out my code line by line to see where the error is happening. There is a segment fault in this function!
Yet, if I make the >= just a > then the segment fault disappears! But...why would that be the case? It makes no sense to me that m can't be negative. Do any of you know why? EDIT: After doing some more comment-checking, I reached this:
This creates the segment fault, yet when I comment out mult_array[2] = arr[2];//shoudl be i it gets rid of the segment fault.Again, I can't see why, however. | |||||
|
Last edited on
|
|||||