Array Probelm

This is a discussion on Array Probelm within the C Programming forums, part of the General Programming Boards category; hi I am haveing an arrary problem, can any1 give me a hint please. Code: int matrix[MATRIX_SIZE][MATRIX_SIZE]; int matrix_data[4][MATRIX_SIZE][MATRIX_SIZE]; { ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    85

    Array Probelm

    hi
    I am haveing an arrary problem, can any1 give me a hint please.

    Code:
    int matrix[MATRIX_SIZE][MATRIX_SIZE];
    int matrix_data[4][MATRIX_SIZE][MATRIX_SIZE];
    {
        matrix_data[0][MATRIX_SIZE][MATRIX_SIZE] = {{0}};
        matrix_data[1][MATRIX_SIZE][MATRIX_SIZE]= {{1}};
      //  //--------------------------------------------------------------//
      //  //--------------------------------------------------------------//
        return matrix_data[0];
    }
    int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];
    
    
        
    ///////////////////////////////////////////char to int//////////////
    void output_program(struct prog *progp)
    {
      char *codep = progp->code;
      int token;
        
        while (token = *codep++)
         fputs(token_table[token].name, stdout);
      putchar('\n');
    }
    
    
    void print_matrix(void)
    {  int i, j; char symbs[] = " OX";
    
       for (i=0; i < MATRIX_SIZE; i++)
       {  for (j=0; j < MATRIX_SIZE; j++)
              putchar(symbs[trace_matrix[i][j]]);
          putchar('\n');
       }
    }
    in the above code i am trying to create and array wit 4 space. to store 4 maps.
    [0] - random map; [1],[2],[3] are pre positioned map. (not create yet)
    I am trying to only store the random map now.

    Code:
    int main()
    {
        int n;
        for (n=0; n<4; n++);
            //result += matrix_data[n];
        printf("%d\n", matrix_data[n]);
        //std::cout<< matrix_data <<std::enl;
        //cout << result
        return 0;
    //////////////////////////////////////////////////////////////////////
    
    {
        //////////I have set it to the array zero for random generat maze///
    int x; 
    srand(time(0));
    for (x = 0; x < 300; x++) matrix_data[0][rand()%MATRIX_SIZE][rand()%MATRIX_SIZE] = 1;
    printf("%d\n", 1); 
    
    
    {
      int i; time_t start;
    
      seed = time(NULL);
      time(&start);
      
      for (run=1; run <= NUM_RUNS; run++)

    Code above is for the random map to generate food.

    However the array is not working


    Can any1 help me please
    thanks very much

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    This is probably not what you want:
    Code:
     for (n=0; n<4; n++);
    Todd
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    any recommandation that i need to do to modify the code?
    any idea??
    thanks thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
        matrix_data[0][MATRIX_SIZE][MATRIX_SIZE] = {{0}};
        matrix_data[1][MATRIX_SIZE][MATRIX_SIZE]= {{1}};
    This won't compile - you would need a loop to set the variables.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    that's wt i was thinking.. coz i need to allow user to choose maze..
    So how should create the loop? While loop i think?

    plz help thx

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    So how do i use the input from the user to choose the correct array?

    get's more diffcult and diffcult..

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    I think for-loop is wt i want? But where should i put it and hwo to read and choose the array??

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by peacealida View Post
    I think for-loop is wt i want? But where should i put it and hwo to read and choose the array??
    You should put your for-loop to initialize the mazes in code that happens before you ask the user to do anything. Do you have an "initialize stuff" section? Well, you do now.

    You can have the user input a number, make sure the number is 0, 1, 2, or 3, and then use that as the index.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

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