![]() |
|
#1
|
|||
|
|||
Calling functions within a functionHi,
I was under the impression you can call a function from within a function. (hell recursions calling the same function within a function) so why am i getting errors with the code (attatched, cause its pretty big)? Its the status function that i've highlighted, i'm getting compiler errors regarding the "definition" of the function. I imagine it is the arguments to the function (I'm still pretty new, so pointers are not my forrté) Any help would be greatly appreciated Mitch |
|||
|
#2
|
||||
|
||||
|
Hi spud. There a couple of problems that I see. First of all your functions need to be defined prior to calling them. So you either need to move your status function above your move function or do a definition at the top of your file like:
CPP / C++ / C Code:
It is actually not a bad idea to do this, maybe even in a seperate header file for all of your functions (except main )Also, when you call status in this context: CPP / C++ / C Code:
You are passing the address of myRover, when you actually should just pass myRover. HTH |
|
#3
|
|||
|
|||
|
Quote:
Cheers! It doesnt like my definition I'll play with headers one day. I have tried the declarati you said, and i cant see anything wrong with it, it returns nothign so the void is fair, and the rover *, location ** seems right. I swear lately C has driven me almost into using face.... though not yet.Thank you for your reply dsmith, its appreciated. Mitch |
|
#4
|
||||
|
||||
|
Hi Mitch. What is the error you are getting?
Maybe try: CPP / C++ / C Code:
My compiler doesn't need the variable names, but maybe yours does. Also, make sure this definition is below the declaration of your structures for location and rover. I think I told you to put it at the top of the file HTH |
|
#5
|
|||
|
|||
|
Thats prob what it is then, i have put it just under the #includes...
It compiles now, so thank you! also, a side note: is this allowed: Code:
Its also giving me hassle and not letting me carry on with the bits i need to. The full code is above, but basically myRover is a structure containing a current x and current y and a map. the map is a 2d array of structures, with each "location" containing information such as an object id (such as 1=rock, 2=pool) i'm trying to access the object id, based on only knowing the current_x and current_y position, know what I'm getting at? Any help again would be greatly appreciated. Mitch |
|
#6
|
|||
|
|||
|
Quote:
you know when you read the preview, looks fine, post then read the actual post and answer your own question... skip the myRover bit, yeah i thought so Cheers for your help dsmith, really sorted me out! Thanks again, Mitch |
Recent GIDBlog
Configuring iptables for Webmin Servers Index Module by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| run script command on ns2.26 | newbie06 | Computer Software Forum - Linux | 66 | 16-Jan-2010 10:53 |
| Flex and bison coding | lucky88star | C++ Forum | 5 | 24-Dec-2007 11:57 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 16:19 |
| Arrays as function arguments - return arrays from functions | pisuke | C Programming Language | 2 | 25-Jul-2007 11:03 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The