Explore BrainMass

Find / resolve c program segmental fault

Need some assistance finding / repairing segmentation fault in program.

The attached program uses a random number generator, orders numbers hi to low, displays hi number, low number and should display mean and median numbers from random list. I run "./random2 1 100 20" to generate 20 numbers between 1 and 100, (./random2 min max number).

My attached program compiles using gcc -Wall -ansi -o random2 Assign2bm.c.

However, when I run "./random2 1 100 20" for example it seg faults after displaying largest number and smallest number without displaying mean and median.


Solution Preview

Hi there!

The seg faults were happening in the following three lines:
*medval=(table[number/(int)2] + ...