| View previous topic :: View next topic |
| Author |
Message |
Varreon Advanced Cheater
Reputation: 0
Joined: 13 Jun 2007 Posts: 80
|
Posted: Wed Jul 11, 2007 12:18 pm Post subject: C++ array as argument |
|
|
I've declared an array:
POINT inv[29];
I wrote a function:
void dropinv(POINT bag[]){
int cur=1;
while(cur<=29){
mouse_event(MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_ABSOLUTE,bag[cur].x,bag[cur].y,0,0);
Sleep(10);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_ABSOLUTE,bag[cur].x,bag[cur].y+44,0,0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(10);
}
}
----------
Still No Errors Here.
When I try to call my function, I just can't seem to do it.
This is my attempt:
dropinv(inv[]);
it sais expression syntax error.
Can an array not be passed as an argument?
_________________
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Wed Jul 11, 2007 12:25 pm Post subject: |
|
|
| you cannot have an array as an argument, just pass a pointer to the array
|
|
| Back to top |
|
 |
Varreon Advanced Cheater
Reputation: 0
Joined: 13 Jun 2007 Posts: 80
|
Posted: Wed Jul 11, 2007 12:32 pm Post subject: |
|
|
so i would do:
dropinv(&inv[])
Right? That doesn't work for me either
_________________
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Wed Jul 11, 2007 12:38 pm Post subject: |
|
|
an example:
| Code: |
#include <stdio.h>
#define MANY 25
typedef struct {
int Int1;
int Int2;
} inv;
void Display(inv* invs);
void main( )
{
inv Manyinvs[MANY]; int i;
puts("Filling array.");
for(i = 0; i < sizeof(Manyinvs)/sizeof(inv); i++)
{
Manyinvs[i].Int1 = rand();
Manyinvs[i].Int2 = i;
}
puts("Calling Display");
Display(&Manyinvs[0]);
puts("Done.");
exit(0);
}
void Display(inv* invs)
{
int i;
for(i = 0; i < MANY; i++)
{
printf("invs[%d].Int1 = %d\n", i, invs[i].Int1);
printf("invs[%d].Int2 = %d\n", i, invs[i].Int2);
}
}
|
|
|
| Back to top |
|
 |
Varreon Advanced Cheater
Reputation: 0
Joined: 13 Jun 2007 Posts: 80
|
Posted: Wed Jul 11, 2007 2:27 pm Post subject: |
|
|
thanks! worked perfectly!
*Edit*
Just double checking, but when you call your function, you can have any number in the brackets, right?
ex:
dofunction(&num[anynumber]);
since it just needs the array, right?
_________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Wed Jul 11, 2007 6:06 pm Post subject: |
|
|
Array[0] is the first element of the array. In C, the first element is the beginning of a region in memory the size of one element times the number of elements. This region is continuous. So by passing in the address of array[0], you're passing in the address of the array as well.
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
|