我对while循环和开关有问题 开关块中的break语句在开关循环时脱离了开关,但没有脱离封闭的循环。我刚刚发现,错误在scanf(“%s”,NamePlayer)中,我缺少一个“&”,就像这个scanf(“%s”,NamePlayer)。可能不是!如果N
我对while循环和开关有问题我对while循环和开关有问题 开关块中的break语句在开关循环时脱离了开关,但没有脱离封闭的循环。我刚刚发现,错误在scanf(“%s”,NamePlayer)中,我缺少一个“&”,就像这个scanf(“%s”,NamePlayer)。可能不是!如果N,c,C,我对while循环和开关有问题 开关块中的break语句在开关循环时脱离了开关,但没有脱离封闭的循环。我刚刚发现,错误在scanf(“%s”,NamePlayer)中,我缺少一个“&”,就像这个scanf(“%s”,NamePlayer)。可能不是!如果NamePlayer是char[]字符串,则隐含地址运算符。然后对简单的char变量使用“%s”格式(添加&)将导致未定义的行为。强烈建议从默认代码块中删除对scanf()的调用 while(Game == 0) { gotoxy(100
开关
块中的break
语句在开关
循环时脱离了开关
,但没有脱离封闭的循环。我刚刚发现,错误在scanf(“%s”,NamePlayer)中,我缺少一个“&”,就像这个scanf(“%s”,NamePlayer)。可能不是!如果NamePlayer
是char[]
字符串,则隐含地址运算符。然后对简单的char
变量使用“%s”
格式(添加&
)将导致未定义的行为。强烈建议从默认代码块中删除对scanf()
的调用
while(Game == 0)
{
gotoxy(100,40);
setForeColor(MY_COLOR_WHITE);
printf("A- Jogar uma partida de Anabi\n");
gotoxy(100,42);
printf("B- Carregar partida anterior\n");
gotoxy(100,44);
printf("C- Descri%c%co do jogo\n", 135, 198);
gotoxy(100,46);
printf("D- Sair do jogo\n");
scanf("%c", &choice);
switch(choice)
{
//This part of the code should break my loop
case 'A':
case 'a':
gotoxy(100, 52);
printf("Please enter your name bellow\n");
gotoxy(98, 53);
printf("->");
scanf("%s",NamePlayer);
Game = 1;
break;
case 'B':
case 'b':
// in here I am going to call a function, the function that reads the file previously saved
//also here I am going to know if there is any saved files, and give an output to the user
break;
case 'C':
case 'c':
//This gets me to the description of the game, rules, etc.. and its working fine with the loop
DescricaoDoJogo();
break;
case 'D':
case 'd':
exit(0);
break;
default:
//This default is giving me trouble, should I use and If, else? Because when i choose the option C, and I get back to the menu what is inside the default executes
printf("Wrong choice.. Try again.. A, B, C or D..");
scanf(" %c", &choice);
system("cls");
break;
}
}