我正在尝试创建一个将根据用户输入的内容调用函数的switch语句,但每次我将需要完成的所有内容都放入函数中时它就无法正常工作。我实际上是在正确地称它吗?
/*two functions I am using*/
void MoveUp(char *move, int *place, char temp[ ], struct Player *Data, struct board room[ ]);
void Movement(char *move, int place, char temp[ ], struct Player Data, struct board room[ ]);
/*function calling MoveUp function which actually does all the work*/
void Movement(char *move, int place, char temp[], struct Player Data, struct board room[ ])
{
printf("Please Enter move: ");
*move = getchar();
getchar();
if(*move == 'k')
{
MoveUp(&*move, &place, temp, &Data, room);
}
else if(*move == 'q'){DataDisp(Data);}
}
函数MoveUp
必须修改变量,但Movement仅修改char move。
当我将MoveUp
函数内部的所有内容放在if语句中(这意味着是一个开关:P)时,一切正常,但是当我把它放在函数中时。
答案 0 :(得分:0)
如果这些功能应该修改struct Player
,那么您使用Movement()
调用struct Player Data
这一事实意味着您制作副本并且您所做的更改将被丢弃返回。
将其更改为指针:
void Movement(char *move, int place, char temp[ ], struct Player * Data, struct board room[ ]);
答案 1 :(得分:-1)
你的函数有这样的变量:
void MoveUp(char *move, int *place, char temp[ ], struct Player *Data, struct board room[ ]);
void Movement(char *move, int place, char temp[ ], struct Player Data, struct board room[ ]);
char *,另一个函数采用相同的类型,因此必须使用:
调用它MoveUp(move, place, ...);
没有&或者*