Advertisement

Array problem

Started by November 28, 2002 08:02 PM
2 comments, last by 42 21 years, 11 months ago

  
//Draw Map


#include "Theef_map.h"

const int max_x=10,max_y=10;
const char* char_draw[]={" ","#","/","!","^"};

//Draw teh maporz (sic)

int draw_map(int **map)
{
    int x=0,y=0;
    while(x<=max_x)
    {
        y=0; //Re-assert that y does = 0

        while(y<=max_y)
        {
                gotoxy(x,y);
                cout<<char_draw[map[y][x]]; //Draw the char that corresponds

                y++;
        }
        x++;
    }
}
  

  
//Map


int current_map[100][100];

int dungeon[5][13]={
{1,1,1,1,1,1,1,1,1,1,0,0,0},
{1,0,0,0,0,0,0,0,0,1,1,1,1},
{1,0,0,3,0,3,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,2,1,1,1,1,1,1,1,1}
};

int town[6][9]={
{1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,1},
{1,0,4,0,0,4,0,0,1},
{1,0,0,0,0,0,0,0,1},
{1,0,0,0,4,0,0,0,1},
{1,1,1,1,1,1,1,1,1}
};
  

  
//Main

#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include "Theef_DrawMap.h"

int main(int argc, char *argv[])
{
  cout << "THEEF";
  draw_map(town);
  system("PAUSE");	
  return 0;
}
  
Error: 9 C:\Dev-Cpp\Theef_main.cpp passing `int (*)[9]'' as argument 1 of `draw_map(int **)''
You seem to be passing the whole town array to the draw_map function...which is expecting a pointer.

Advertisement
It won't work this way. hmm... Let's see:
  void fn(int array[6][]);//                ^------- you must have thisint town[6][9] = {...};//       ^---------------- must be samefn(town);   

And remember, two-dimensional array and double-pointer have different meaning. Be careful with that.

[edited by - DerekSaw on November 28, 2002 11:32:32 PM]
"after many years of singularity, i'm still searching on the event horizon"
IIRC, every dimension except the first needs to match whatever you''re trying to pass the array to.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement