Thread: Sorting 3D matrix (Segmentation Fault)

  1. #16
    C <3er
    Join Date
    Jul 2011
    Aaah okey I didn't get what you were trying to say, ok will try that out to see if it works... thanks
    Will come with the results soon

    Ok changed:
    table tmp;
    tmp.cell[j] = t->cell[j];
    t->cell[j] = t->cell[j+1];
    t->cell[j+1] = tmp.cell[j];
    char **tmp;
    tmp = t->cell[j];
    t->cell[j] = t->cell[j+1];
    t->cell[j+1] = tmp;
    Is this what you meant? BTW and very important I realised how stupid I am just when I read the while loop and found it was wrong, order = 1; should be out of the for loop not inside of it... changing this and doing what tabstop suggested seems to solve the segmentation fault... just tested once so I'll keep testing and will come back u.u

    EDIT 2:
    Tested various times and it works as expected
    So if the replacement is what you meant tell me please so I'm confident enough that this is alright and solved ok?
    p.s.: I feel sooo stupid lol... at least I don't need now a table tmp...
    Last edited by beta3designs; 08-01-2011 at 04:12 AM.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Yes, that's what you want to use to swap. This is one place (perhaps the only one place) where the weirdness of dynamic higher-dimension arrays actually helps you; if this had been a real array you would have had to swap the entire row (although rather than loop through it you'd probably just use memcpy).

  3. #18
    C <3er
    Join Date
    Jul 2011
    Ok thank you very much! It is in deed working now ^^
    I have another problem with higher-dimension dynamic arrays so I'll open a new thread because it has nothing to do with this is more of a memory issue...
    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault?
    By Camambert in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2009, 11:21 AM
  2. Pointer to a matrix - Segmentation fault
    By endomlic in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 12:24 AM
  3. Segmentation Fault :(
    By DarkDot in forum C++ Programming
    Replies: 39
    Last Post: 04-07-2007, 04:16 AM
  4. segmentation fault : matrix multiplication ??
    By gemini_shooter in forum C Programming
    Replies: 11
    Last Post: 06-24-2005, 09:50 AM
  5. segmentation fault and memory fault
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 04-02-2002, 11:09 PM

Tags for this Thread