damn arrays

This is a discussion on damn arrays within the C Programming forums, part of the General Programming Boards category; Hi everyone, Can anyone tell me how I would turn a 64x64 array into a 3x4096 array. The first column ...

  1. #1
    Unregistered
    Guest

    Unhappy damn arrays

    Hi everyone,

    Can anyone tell me how I would turn a 64x64 array into a 3x4096 array. The first column needs to contain the x co-ord of the element the second column contains the y co-ord of the element and the third column needs to contain contain the value of that element.

    Any help would be great!

    Thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Something like
    Code:
    for ( r = 0 ; r < 64 ; r++ ) {
      for ( c = 0 ; c < 64 ; c++ ) {
        pos = r * 64 + c;
        new[pos][0] = r;
        new[pos][1] = c;
        new[pos][2] = old[r][c];
      }
    }

  3. #3
    Unregistered
    Guest
    Thanks for that Salem but could you possibly explain whats going on there.

    cheers

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > The first column needs to contain the x co-ord
    Is this line....
    new[pos][0] = r;

  5. #5
    Unregistered
    Guest
    ah ok, thats excellent.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  4. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 12:48 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

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