我试图让一个函数从我的main()函数传递一些整数指针并为它们赋值.但是,我的程序在分配值时崩溃.这是我的代码:
int computeMoveLocation(int* r, int* c, char* board)
{
//some code up here
*r = 0; //This breaks the program
*c = 0;
}
Run Code Online (Sandbox Code Playgroud)
我不是想改变指针的地址 - 我试图改变指向的整数的值.但是,我显然做错了什么.
任何帮助将不胜感激.
编辑: 这是main()的相关代码.如果我还要包含其他任何内容,请告诉我.
int main()
{
//initialization code
//...
while (1)
{
switch (MACHINE_STATE)
{
case COMPUTER_MOVE :
{
//check rows for three Xs
//check columns for three Xs
//check diagonals for three Xs
//otherwise, move anywhere else
int *r, *c;
computeMoveLocation(r, c, board);
computerMove(*r,*c, board);
PREVIOUS_STATE = COMPUTER_MOVE;
MACHINE_STATE …Run Code Online (Sandbox Code Playgroud)