Like Tree2Likes

Sorting 3D matrix (Segmentation Fault)

This is a discussion on Sorting 3D matrix (Segmentation Fault) within the C Programming forums, part of the General Programming Boards category; Aaah okey I didn't get what you were trying to say, ok will try that out to see if it ...

  1. #16
    C <3er
    Join Date
    Jul 2011
    Posts
    46
    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
    EDIT:

    Ok changed:
    Code:
    table tmp;
    tmp.cell[j] = t->cell[j];
    t->cell[j] = t->cell[j+1];
    t->cell[j+1] = tmp.cell[j];
    to:
    Code:
    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 05:12 AM.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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
    Posts
    46
    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!

Page 2 of 2 FirstFirst 12
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, 12:21 PM
  2. Pointer to a matrix - Segmentation fault
    By endomlic in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 01:24 AM
  3. Segmentation Fault :(
    By DarkDot in forum C++ Programming
    Replies: 39
    Last Post: 04-07-2007, 05:16 AM
  4. segmentation fault : matrix multiplication ??
    By gemini_shooter in forum C Programming
    Replies: 11
    Last Post: 06-24-2005, 10: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21