Thread: Large 1D array -> Grid-like 2D array. HOW?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    45

    Exclamation 1D array to 2D array conversion help!

    Hello.

    Im making a game for a certain community and I can load in these map levels. Each level is exactly 592 bytes -

    30x20 (30 chars to the right, 20 down) + end of line char and '\n' char. Oh but hte last line is the password for hte level so its only 4x20 if it wree gridded.

    Anyways, Im trying to grid it like that in a 2D array. My function:

    Code:
    void WorkWithMap() {
         for(i=0;i<19;i++) {
                           for(z=0;z<30;z++) {
                                             
                                             level[i][z]=map[i*z];
                                                                                 
                           }
         }
    }
    I dont WANT the password in there, so i didnt read up to 20 (hence i<19). This way doesnt work as when printing out, its all random and multiple characters where there is only one of in the file. So... Please help?

    I believe one reason is because if

    i=0

    and z=... say...

    z=23

    Than

    level[i][z] = map[ 0 * 23 ]

    thus resulting in map[0] through out the entire thing... Any way to make it work?
    Last edited by SG57; 11-05-2006 at 07:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array -> 2D array
    By Tupcia in forum C Programming
    Replies: 4
    Last Post: 05-16-2008, 02:29 AM
  2. passing/pointing to a 2d array
    By jamie85 in forum C Programming
    Replies: 7
    Last Post: 10-28-2005, 10:16 PM
  3. Copying from one 2d array to another....with a twist
    By Zildjian in forum C++ Programming
    Replies: 2
    Last Post: 10-24-2004, 07:39 PM
  4. Replies: 6
    Last Post: 10-21-2003, 09:57 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM