| View previous topic :: View next topic |
| Author |
Message |
123qwe Newbie cheater
Reputation: 0
Joined: 26 Dec 2006 Posts: 21
|
Posted: Thu Jan 22, 2009 4:27 am Post subject: C++ Functions |
|
|
hello
how would i Load a txt file when my program starts and retrieve values from it before anyhting else happens?
and yes i know this code below doesnt work but i hope u understand what i need help with thanks.
e.g.
void loadtxt()
{
bla bla
return ARRAY (how do i do that?)
}
main()
{
loadtxt();
cout << ARRAY[1];
} |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jan 22, 2009 4:45 am Post subject: |
|
|
first thing.
you cant return array when you declared a void function
if you want to return other value then void
replace the void with the type of value returned |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Jan 22, 2009 5:35 am Post subject: |
|
|
| Code: | #include <stdlib.h>
char *func()
{
char *c; // =malloc(512);
//..
return c;
}
int main(int argc, char *argv[])
{
char *c;
c = func();
// dealloc(c);
return 0;
} |
| Code: | #include <stdlib.h>
void func(char *c)
{
// Do something with c, eg.
c[0] = 'a';
return;
}
int main(int argc, char *argv[])
{
char *c = malloc(1);
func(c);
dealloc(c);
return 0;
} |
You might also want to return the length of c. I wrote it with C, but w/e, you got the point. Also, here you don't actually return the array, but a pointer to memory where the stuff is. |
|
| Back to top |
|
 |
simondaking How do I cheat?
Reputation: 0
Joined: 28 Nov 2008 Posts: 4
|
Posted: Thu Jan 22, 2009 10:48 am Post subject: |
|
|
Here is some code that shows you how to open a file and read its contents...
| Code: | #include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
cout << "enter file name to read: ";
string filename;
getline(cin, filename);
fstream fin(filename.c_str());
while(fin)
cout << (char)fin.get();
}
|
|
|
| Back to top |
|
 |
123qwe Newbie cheater
Reputation: 0
Joined: 26 Dec 2006 Posts: 21
|
Posted: Thu Jan 22, 2009 6:44 pm Post subject: |
|
|
i'll give u my code and i'll show u what i mean =]
| Code: |
VOID LOAD()
{
int turk[2];
ifstream turka("repot.txt");
int inaa;
int poooo = 0;
while(turka >> inaa)
{
turk[poooo] = inaa;
poooo++;
}
}
DWORD WINAPI leftclick(LPVOID)
{
//DO LEFT CLICK HERE AT CURSOR POINT TURK[0], TURK[1]
return 0;
}
int main()
{
load();
//IF NUMPAD 1 is pressed CREATE THREAD
return 0;
}
|
i have to load the variables from the file first cause once the game is loaded it uses to much resources and the file doesnt get opened quickly enough. when i try the above code it doesnt work(other then the obvious things i left out on purpose lol, otherwise the code is to big), it says undeclared turk[0]. |
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Thu Jan 22, 2009 7:34 pm Post subject: |
|
|
As is.. "turk" only exists in load(), you need to declare it in the global scope for other functions to access it.
| Code: | int turk[2]; // global variable
void load()
{
int turk[2]; // local variable, only available within this code block.
...
}
|
|
|
| Back to top |
|
 |
123qwe Newbie cheater
Reputation: 0
Joined: 26 Dec 2006 Posts: 21
|
Posted: Fri Jan 23, 2009 11:20 pm Post subject: |
|
|
omg i missed that LOL
thanks so much!!!! |
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Sat Jan 24, 2009 3:28 am Post subject: |
|
|
pseudo code
GetWindowRect
calcute where pots are...(should work for any size window...(use GetPixel To find red and blue or w/e color your pots are)
use MouseMove and mouse_event to simulate hitting the pots and or find the hotkeys to use the pots?(most games have that now..)
and just use PostMessage to simulate key strokes alternitvly keybd_event would suffice..
regargs BanMe |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Jan 24, 2009 8:03 am Post subject: |
|
|
| BanMe wrote: | pseudo code
GetWindowRect
calcute where pots are...(should work for any size window...(use GetPixel To find red and blue or w/e color your pots are)
use MouseMove and mouse_event to simulate hitting the pots and or find the hotkeys to use the pots?(most games have that now..)
and just use PostMessage to simulate key strokes alternitvly keybd_event would suffice..
regargs BanMe |
type the wrong thing? _________________
|
|
| Back to top |
|
 |
|