Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ array as argument

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Varreon
Advanced Cheater
Reputation: 0

Joined: 13 Jun 2007
Posts: 80

PostPosted: Wed Jul 11, 2007 12:18 pm    Post subject: C++ array as argument Reply with quote

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
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Wed Jul 11, 2007 12:25 pm    Post subject: Reply with quote

you cannot have an array as an argument, just pass a pointer to the array
Back to top
View user's profile Send private message
Varreon
Advanced Cheater
Reputation: 0

Joined: 13 Jun 2007
Posts: 80

PostPosted: Wed Jul 11, 2007 12:32 pm    Post subject: Reply with quote

so i would do:
dropinv(&inv[])
Right? That doesn't work for me either
Sad

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Wed Jul 11, 2007 12:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
Varreon
Advanced Cheater
Reputation: 0

Joined: 13 Jun 2007
Posts: 80

PostPosted: Wed Jul 11, 2007 2:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Wed Jul 11, 2007 6:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites