我最近刚开始学习Objective C,当我运行下一个程序时,我收到错误“程序接收信号:”EXC_BAD_ACCESS“对于代码行
if([*userChoice isEqualToString:@"yes"])
完整的代码是:
void initGame (void);
void restartGame(void);
void toGoOn(char *playerChoice);
int guess=-1;
int from=-1;
int to=-1;
bool playStatus=true;
bool gameStatus=true;
int answer=-1;
NSString *userChoice[10];
//if true the game is on
int main (int argc, const char * argv[])
{
@autoreleasepool {
GuessManager *game=GUESS;
NSLog(@"Hello, lets play");
NSLog(@"Please provide a positive range in which you would like to play");
do{
initGame();
[game setnumberToGuess:from :to];
do {
printf("Make you guess:");
scanf("%d", &guess);
[game setUserGuess:guess];
[game checkUserGuess];
if([game getDidIgetIt])
{
playStatus=false;
}
else
{
playStatus=true;
}
} while (playStatus);
restartGame();
}while(gameStatus);
printf("Thanks For Playing PanGogi Games! GoodBye");
}
return 0;
}
void initGame (void)
{
printf("from:");
scanf("%d",&from);
printf("to:");
scanf("%d",&to);
}
void restartGame(void)
{
printf("Would you like to continue?(yes/no)");
scanf("%s",&userChoice);
//scanf("%d",&answer);
// if(answer==1)
if([*userChoice isEqualToString:@"yes"])
{
gameStatus=true;
}
else
{
gameStatus=false;
}
}
我知道它与 NSString 变量 userChoice 以及它在 if 中的使用方式有关,但我找不到的是我做错了什么。
请帮忙 :)