这主要是出于好奇为什么会发生这种情况,因为在我的情况下并不重要。如果我输入一个无效的数字,它会正确地转到重复标签并要求我再次输入一个数字,但如果我输入一个像“f”这样的字符,它将无限循环并且不会停止。为什么是这样?
这里的数组和所有变量都是 int 类型。
repeat:
printf("Enter number of available space, you are %c: ", userXO);
scanf("%d", user);
switch (*user)
{
case 1: if (spaces[0][0] == 49){ spaces[0][0] = userXO;}else goto repeat; break;
case 2: if (spaces[0][1] == 50){ spaces[0][1] = userXO;}else goto repeat; break;
case 3: if (spaces[0][2] == 51){ spaces[0][2] = userXO;}else goto repeat; break;
case 4: if (spaces[1][0] == 52){ spaces[1][0] = userXO;}else goto repeat; break;
case 5: if (spaces[1][1] == 53){ spaces[1][1] = userXO;}else goto repeat; break;
case 6: if (spaces[1][2] == 54){ spaces[1][2] = userXO;}else goto repeat; break;
case 7: if (spaces[2][0] == 55){ spaces[2][0] = userXO;}else goto repeat; break;
case 8: if (spaces[2][1] == 56){ spaces[2][1] = userXO;}else goto repeat; break;
case 9: if (spaces[2][2] == 57){ spaces[2][2] = userXO;}else goto repeat; break;
default: goto repeat; break;
}