Hi, I'm a newbie and I have to make the following assignment.
We are asked to use this function
void get_input(char P[3][3], int *line, int *column);
It is a part of a tic-tac-toe game and we have to use the above function
in order to ask the player to give the coordinates of the cell. In that cell will be placed the letter "X".
I have many problems.
I have written the code and if I use it without a function (just place it directly in the main code) it works fine.
But we have to use the above function, and the coordinates should be returned to the main programm by reference.
When I try to place it in a function I get confused.
Fist of all I want to ask, in which order are the values passed to the function.
What I mean is that,
first I will ask the player for the "line" and "column"
then I have to pass to the array (P[3][3])) the character "X", according to the values of "line" and "column".
Therefore the
1st value that I get is the value of "line"
2st value that I get is the value of "column"
3d value that I declare according to the value of "line" and "column" is the X in the P array.
But the order of the values in the function are (char P[3][3], int *line, int *column)
1st value "X" in the array
2st value of "line"
3d value of "column"
Does this mean that the fist value that I get (and that value is "line") goes to the first value in the parenthesis of the function, which is the "char P[3][3])?
How to I place an order to that mess.
Here is part of the code, where you can see how I call the function in the main program.
The problem is that when I print the values of the function in order to check what I've done, I get crazy things.
for example
for input: line = 1, column=1, character =X,
when I print them, I get
line= ' , column= 8 , character = 4006960
We are asked to use this function
void get_input(char P[3][3], int *line, int *column);
It is a part of a tic-tac-toe game and we have to use the above function
in order to ask the player to give the coordinates of the cell. In that cell will be placed the letter "X".
I have many problems.
I have written the code and if I use it without a function (just place it directly in the main code) it works fine.
But we have to use the above function, and the coordinates should be returned to the main programm by reference.
When I try to place it in a function I get confused.
Fist of all I want to ask, in which order are the values passed to the function.
What I mean is that,
first I will ask the player for the "line" and "column"
then I have to pass to the array (P[3][3])) the character "X", according to the values of "line" and "column".
Therefore the
1st value that I get is the value of "line"
2st value that I get is the value of "column"
3d value that I declare according to the value of "line" and "column" is the X in the P array.
But the order of the values in the function are (char P[3][3], int *line, int *column)
1st value "X" in the array
2st value of "line"
3d value of "column"
Does this mean that the fist value that I get (and that value is "line") goes to the first value in the parenthesis of the function, which is the "char P[3][3])?
How to I place an order to that mess.
Here is part of the code, where you can see how I call the function in the main program.
The problem is that when I print the values of the function in order to check what I've done, I get crazy things.
for example
for input: line = 1, column=1, character =X,
when I print them, I get
line= ' , column= 8 , character = 4006960
Code:
#include <stdio.h>
#include <stdlib.h>
void get_input(char P[3][3], int *line, int *column);
int main()
{
char P[3][3];
int l, c;
get_input(P, &l, &c);
printf("%c %d %d\n", P, l, c);
system("PAUSE");
}
void get_input(char P[3][3], int *line, int *column)
{
(here is some code)
.
.
.
printf("Choose cell (line, column):");
scanf("%d %d", &l, &c);
D[l][c]='X';
Comment