我的问题是这个函数返回guess 作为97 和y 的总和,而不仅仅是字母,正如switch 语句所指示的那样。奇怪的是,当我拥有它时,它只是返回 y,它的工作方式完全符合我的预期。例如,当 y=4,并且我让它返回 y 时,显示 4。当 y=4 并返回 'guess' 时,显示 101。免责声明:这不是完整的代码。它真的很长,而且我认为是多余的,因为我唯一的问题是当这个特定函数返回“猜测”时,即使它返回 y 也不行。如果所有代码都有用,我很乐意把它放上来。
int letterguess(int z){
char guess;
int y;
y=letters[0][z];
switch (y){
case 0:
guess='a';
break;
case 1:
guess='b';
break;
case 2:
guess='c';
break;
case 3:
guess='d';
break;
case 4:
guess='e';
break;
case 5:
guess='f';
break;
case 6:
guess='g';
break;
case 7:
guess='h';
break;
case 8:
guess='i';
break;
case 9:
guess='j';
break;
case 10:
guess='k';
break;
case 11:
guess='l';
break;
case 12:
guess='m';
break;
case 13:
guess='n';
break;
case 14:
guess='o';
break;
case 15:
guess='p';
break;
case 16:
guess='q';
break;
case 17:
guess='r';
break;
case 18:
guess='s';
break;
case 19:
guess='t';
break;
case 20:
guess='u';
break;
case 21:
guess='v';
break;
case 22:
guess='w';
break;
case 23:
guess='y';
break;
case 24:
guess='y';
break;
case 25:
guess='z';
break;
}
return guess;
}
我真的看不出这怎么可能会这样搞砸。提前致谢。