Computer Science Canada Help cant call on function. |
Author: | Al_ [ Sun May 24, 2009 11:45 am ] | ||
Post subject: | Help cant call on function. | ||
Hi. to those who will have helped me, thank you in advance. Heres the code: im trying to make a tic tac toe game with arrays.
Im using Dev-C++. Error message: in function 'int main()': invalid conversion from 'int' to 'int(*)[3]' Line 30 initializing argument 1 of 'int check(int(*)[3])' Line 30 |
Author: | DtY [ Sun May 24, 2009 1:06 pm ] | ||||
Post subject: | RE:Help cant call on function. | ||||
You want to pass a reference to the array, not the alement [3][3], the call should look like:
Also, in a lot of your ifs, you have stuff like:
The "=" in C++ means assignment, what you want here is comparison, which is "==". |
Author: | Al_ [ Sun May 24, 2009 6:13 pm ] |
Post subject: | RE:Help cant call on function. |
Thank you very much for your help. And thanks for noticing the "=" mistake, probably saved me an hour of headaches. |
Author: | Al_ [ Sun May 24, 2009 6:17 pm ] |
Post subject: | RE:Help cant call on function. |
Two quick question: Once i return to the main, after the check() function, are the values for p and the values for each entry in the array saved? And also, if none of the conditions in the if statement are met, then the compiler skips over the if statement and ultimately the check() function does nothing. Is this correct? |
Author: | DtY [ Sun May 24, 2009 6:28 pm ] | ||
Post subject: | RE:Help cant call on function. | ||
First question: Yes, the new values will be saved. This is because arrays are pointers. If you haven't learned about pointers yet, don't worry about it, just know that if you pass an array to a function, and use that function to change a value, it will edit the original. It wont do this for other types though, unless you explicitly pass a pointer. p wont be changed, but since it's a single value, you can return the value of p, rather than changing it in there (so you wont need to pass p at all) Second: That is correct. If you want to make sure it does, add else at the end:
|