这是我的 main.c 中使用的一个函数。问题出在char
任务。
void takeTurn(int *iap, int *tile, char *cap) {
//*iap is 1 right now
printf("\nThe current active player is %d. His character is %c", *iap, *cap);
//prints The current active player is 1. His character is q.
if (*iap == 1) *cap == 'X';
if (*iap == 2) *cap == 'O';
printf("\nThe current active player is %d. His character is %c", *iap, *cap);.
//prints The current active player is 1. His character is q.
. . .
}
需要做什么才能*cap
分配正确的 char
给合适的活跃玩家?
最佳答案
您正在使用 ==
相等比较运算符,而应使用 =
赋值运算符。
更改这些语句:
*cap == 'X';
*cap == 'O';
改为这些:
*cap = 'X';
*cap = 'O';
关于对 *char 的字符分配不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38416207/