pass pointer of 2d char array into function call?

Posted by Nargsbrood on Fri 06 Oct 2006 04:13 AM — 13 posts, 49,901 views.

#0
i am setting up function that needs to receive a pointer to a 2 dimensional char array. the setup is as follows:

i have the function declared in mud.h:
void plot_map args ( ( CHAR_DATA * ch, int vnum, int xcoord, int ycoord, int tier, int * plotted, char * map ) );


declare map:
char *map[19][19];


call recursive function:
plot_map ( ch, ch->in_room->vnum, 9, 9, 0, plotted, map );


function header:
void plot_map ( CHAR_DATA * ch, int vnum, int xcoord, int ycoord, int tier, int * plotted, char * map )
{



i get this syntax error:
Quote:
act_move.c:3057: warning: passing arg 7 of `plot_map' from incompatible pointer type


anyone know how to properly do this?

#1
uh maybe char **map or char ***map; XD
Australia Forum Administrator #2
Well, they are not the same.

This compiled for me without errors:


void plot_map ( CHAR_DATA * ch, int vnum, int xcoord, int ycoord, int tier, int * plotted, char * map [19][19])


Or you might be better off making a typedef, eg:


typedef char * maptype [19][19] ;

...

void plot_map ( CHAR_DATA * ch, int vnum, int xcoord, int ycoord, int tier, int * plotted, maptype map)
{
  }


...

maptype map;

...

plot_map ( ch, ch->in_room->vnum, 9, 9, 0, plotted, map );


Amended on Fri 06 Oct 2006 04:30 AM by Nick Gammon
#3
i've tried a few things and cannot get it to work still:

mud.h declarations:
typedef char maptype  [19][19]  ;
void plot_map args ( ( CHAR_DATA * ch, int vnum, int xcoord, int ycoord, int tier, int * plotted, maptype * map ) );


declare map:
maptype map;


i compile it fine without making any calls to the function. when i then add the function call:
plot_map ( ch, ch->in_room->vnum, 9, 9, 0, plotted, map );


it then gives this same error:
Quote:
act_move.c:3065: warning: passing arg 7 of `plot_map' from incompatible pointer type


-------------

i tried the typedef as
typedef char maptype  [19][19]  ;

as you stated above.
but then it required that i use a * when ever i reference it and so would only let me change the address which was then causing it to crash when i tried to set my values... i want to set the value as 'O' but it would only let me change the address to 'O' which bombs it of course.

anything else come to mind of what i am doing wrong?
Australia Forum Administrator #4
Well, you didn't do what I did:

typedef char * maptype [19][19] ;

You left out the * and then tried to put it in later.
Australia Forum Administrator #5
Or, the way you were doing it:

Quote:

i compile it fine without making any calls to the function. when i then add the function call:

plot_map ( ch, ch->in_room->vnum, 9, 9, 0, plotted, map );



You said you were expecting a pointer to maptype, but only passed it by value. You need to do this:


plot_map ( ch, ch->in_room->vnum, 9, 9, 0, plotted, &map );


Generally when you expect a pointer, you have to take the address with & to generate the pointer.
#6
thanks a lot for the help. i was able to do it using a typedef and paying more attention to your recommendations, nick.

What I was doing was making a mapper system which spiders out to build a map of the current area you are in. It is colorized and builds terrain on the map based on the sector type of the room. You do not have to do any map building for your areas and it can be used with all existing areas and can probably stick into any smaug smaug derivitive without having to port... maybe can go into most merc derivitives? (not familiar with presmaug) The only problem is that the rooms have to make sense logically in their layout. going e, s, w, n should end you back up in the same room you began or else it maps it all wierd and doesnt make sense.

I understand programming concepts and am trying to familiarize myself with c concepts... such as passing pointers of different characteristics and what not. That is why i decided to build this mapper from the ground up. When I was done with it(for the most part, have to add nomap flag for roomflags and exitflags) i decided to look for similar snippets to see how they compare. The only 2 that i saw was the overland map code which looks mighty pretty but isnt really a mapping system in that it gives you the lay out of the actual area room to room. and There was also ackmapper which i didnt feel like porting over to smaug simply to take a look at it and couldnt find any screenshots.

Does anyone know of any working muds that use ackmapper?
Or better yet, have any screenshots or know where some are available?
and does anyone know of any other mapping snippets?


Thanks
Australia Forum Administrator #7
We had a lengthy discussion about mapping in this thread:

http://www.gammon.com.au/forum/bbshowpost.php?id=7306

That discusses working out where each room leads, and the quickest way to get to another one.
#8
its an interesting discussion and something i have planned on doing in the future. thanks.

It's pretty different from what i was trying to do though. I did not need to find the shortest route of anything. was just mapping out the area and wanted to compare the snippet to other snippets others may know of.

here are screenshots:


[image noborder]www.geocities.com/carlinsmith7/maps.GIF[/image]
(dont know tag for adding the image in this forum, info not found under "what are forum codes?" link. I've seen nick do it before so i assume anyone can)

you can see darkhaven is all jumbled up due to shops seemingly extending into roads behind them. This is where you would use the nomap flag on the room so that it maps the exit to the room and will color the exit a specific color to denote it as a shop but not plot the shop on the map.
Amended on Sat 14 Oct 2006 03:16 AM by Nargsbrood
Australia Forum Administrator #9
Yes, I see what you mean now.

Image posting is an administrator-only function. I am trying to keep bandwidth down, plus make it hard for people to post inappropriate images.
USA #10
Quote:
Does anyone know of any working muds that use ackmapper?


Alsherok uses a mapper which I think Zarius derived from ackmapper. You can get a look at it by logging on to alsherok.net 5500 and getting past the chargen process. It probably doesn't do like you've described with the terrain but it's pretty close.

The overland system is my behemoth of a creation. It wasn't designed to be used for in-area mapping. It's designed to be used for the vastness of space between areas. One person I know of even used it to literally become the vastness of outer space between planets.
#11
thanks for pointing out to check out your mud. I can see what a great asset the overland system is. it's pretty awsome. Removes the need to find 200 ways to describe a dirt trail and makes for a lot more possibility in moving around. There is a lot more to it then the actual display of the map.
#12
i noticed a problem with the help files on alsherok

I can type 'help mptriggers' and can see the help file
I was able to see info for
sectortypes
wizhelp
mapedit
mapout

and others.

i was not able to view mset but when i tried to view it typing
help mset,
it said:
no help on 'mset' found.
sugested help files:
MSET