Author |
Message |
Reaem Newbie
Joined: Oct 02 2005 Posts: 9 Offline
|
Posted: Wed Mar 12, 2008 4:13 pm Post subject: baffled by this coding |
 |
|
|
|
void Cbuyship(const char *tc, const char *params, Player *p, const Target *target)
{
int ship = atoi(params);
if (ship < 1 || ship > 8)
return;
ship--; //for convenience
//cost checking
if (!Spend_Pts(p, ship_costs[ship]))
return;
else
{
void *v = HashGetOne(docks, p->name);
dock d;
d = (dock)*v;
if (!d)
{
d = {0,0,0,0,0,0,0,0};
d[ship] = 1;
HashReplace(docks, p->name, d);
}
else
{
d[ship] = d[ship] + 1;
}
}
} |
I get the following errors:
../RTZ/RTZ.c: In function `Cbuyship':
../RTZ/RTZ.c:190: warning: dereferencing `void *' pointer
../RTZ/RTZ.c:190: error: cast specifies array type
../RTZ/RTZ.c:194: error: syntax error before '{' token
../RTZ/RTZ.c:198: error: syntax error before "else"
190 is the line with d = (dock)*v;
The problem is, I'm not sure what to do with the void pointer to cast it into the dock object (If I even need to do that).
dock is just a simple: typedef int dock[8];
I've been programming for awhile, but I'm not certified or even a real c veteran and the void pointer cast to dock type is really owning me.
Thanks in advance,
-R _________________ -JP |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Wed Mar 12, 2008 4:26 pm Post subject: |
 |
|
|
|
what's wrong with d = v?
You can't initialize non-static arrays like that on like 194. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Agile Guest
Offline
|
Posted: Wed Mar 12, 2008 6:44 pm Post subject: |
 |
|
|
|
d=v doesn't work, I've tried countless variations of castings and allocation orders and nothing I do can make this work.
Same incompatible types error |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Thu Mar 13, 2008 9:16 am Post subject: |
 |
|
|
|
This might work:
But as pointed out before the rest of your code is a little iffy anyway. _________________ ss news  |
|
Back to top |
|
 |
Agile Guest
Offline
|
Posted: Thu Mar 13, 2008 5:19 pm Post subject: |
 |
|
|
|
Yeah, the void pointers and arrays by themselves I can deal with, but putting them together scrambles my brain.
I eventually just decided to make it a struct similar to BotData with an array in it =( Maybe I can optimize this later on but I want to get a working server soon.
Thx everyone |
|
Back to top |
|
 |
tcsoccerman Server Help Squatter
Age:33 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Thu Mar 13, 2008 6:58 pm Post subject: |
 |
|
|
|
if this is in devcpp, i've had problems where i forget to make the projecta "c" project instead of a "c++" project. i have spent countless hours trying to figure out the problem.. |
|
Back to top |
|
 |
|