Thread: running through a loop using pointers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    16

    running through a loop using pointers

    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.
    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;
    This is not my whole code, but I know the other parts of the code work, so I am just posting the relevant parts.

    Thanks
    boy
    Last edited by boy; 08-18-2011 at 04:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For loop not running properly
    By Todd88 in forum C++ Programming
    Replies: 21
    Last Post: 04-04-2008, 05:27 PM
  2. Running a program in a loop
    By Robert_Sitter in forum C# Programming
    Replies: 7
    Last Post: 01-27-2006, 10:09 AM
  3. User input while loop is running
    By two31d in forum C++ Programming
    Replies: 7
    Last Post: 11-30-2005, 05:28 PM
  4. functions stops loop from running
    By a1pro in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 02:02 PM
  5. Running triangles through loop
    By shanedudddy2 in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2003, 12:59 AM