我是个新手,但我花了很多时间去理解我在这里做错了什么。。
我使用的是Turbo C,有时候我得到的输出消息实际上是Borland turboc文本的一部分,所以看起来文本并没有存储在char losemsg中。。
void lose(int d) //Different messages for different deaths
{
char *losemsg; //Lose message
setcolor(4);
settextstyle(0,0,1); //Set font size
switch(d)
{
case '1': losemsg="STOP HURTING THE WALL!"; //Hitting the wall
break;
case '2': losemsg="Like all great dictators, you've fallen...!"; //Falling
break;
case '3': losemsg="Oh well, sucks to be you...";
break;
case '4': losemsg="You've been killed by a spike, how sad..."; //Spike
break;
case '5': losemsg="You've been hit by something that defies gravity!";
break;
case '6': losemsg="There is no lifeguard, you've drowned!"; //Drowning
break;
}
outtextxy(100,150,losemsg);
delay(2000);
}
最佳答案
代码看起来很好,除非输入值在'1'
-'6'
之外。在后一种情况下,代码的行为是未定义的(显示的是未初始化指针指向的字符串)。