I am working on a homework assignment an have spent quite some time trying to figure out why my code is not running right when I convert my loop to using pointers. I have gone through and debugged my code and found that it is sending a segmentation fault when it hits the if statement the sends it back through the loop. If anyone can help me it would be greatly appreciated.
This is not my whole code, but I know the other parts of the code work, so I am just posting the relevant parts.Code:#define ARRAY_SIZE 10000 double *array = calloc(ARRAY_SIZE, sizeof(double)); double sum = 0; int *max, *end; max = &end[ARRAY_SIZE]; loop: //loops through array and adds up all elements of array sum = sum + array[0] + array[1] + array[2]; if(*array < *max) // this is where the debugger throws the segmentation fault error goto loop;
Thanks
boy



3Likes
LinkBack URL
About LinkBacks



