1

私は少し初心者ですが、ここで何が間違っているのかを理解するためにかなりの時間を費やしてきました。

Turbo Cを使用していますが、出力メッセージが実際にはBorland Turbo Cテキストの一部である場合があるため、テキストがcharlostmsgに保存されていないようです。

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);
}
4

2 に答える 2

2

入力値が'1'-の外にある場合を除いて、コードは正常に見え'6'ます。後者の場合、コードの動作は未定義です(初期化されていないポインターが指す文字列を表示しています)。

于 2013-03-23T18:55:23.563 に答える
0
...
case '6': losemsg="There is no lifeguard, you've drowned!"; //Drowning
break;

default: /* If you enter not 1..6 then it simply ends wothout strange behaviour. */
break;
}

lostmsgという名前のポインターを作成しました。このポインタは、ある変数を指している必要があります。

目標が次の場合:1)1から6までの数値を入力します。2)入力した数値に応じて、文字列を出力します。私は正しいですか?もしそうなら、以下を読んでください:私はそれcharが1文字を含むかもしれないと思います。ただし、文字列(1文字以上)を覚えておくために、6つの変数を作成できます(6つのchar型の配列を作成します)。

/* You can create them beforehead in the individual file of function */
/* (it's difficult, but it is worth it! =) ) */
char str_1; /* 1..6 */
scanf("%s", &str_1);
printf("%s", &str_1);

また、入力した数値に応じて、必要な文字列を出力します。

于 2013-03-24T19:18:05.843 に答える