•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,817 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2172 | Replies: 1
![]() |
| |
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
below is one of my function call of a program done in C:
/* asks if the players would like to have another game of Tic Tac Toe */
void prompt_user(int game[][SIZE])
{
char reply;
printf("\nPlay Again? (Y/N): ");
scanf("%c", &reply);
if(reply == 'Y' || reply == 'y')
{
print_empty_board();
initialise_board(game);
}
else if(reply == 'N' || reply == 'n')
{
printf("Hope You Have Enjoyed The Game!\n\n");
exit(0); /* quits the game */
}
}
when using microsoft visual C++ and devC++ to compile and execute, there were no errors in the output when playing the tic-tac-toe game.
however, when i used my school's lab (which is using Linux and xemacs only) pc to compile and execute, the output did not allow me to enter Y or N as an answer to 'Play Again?'. The execution exits immediately. anyone knows the reason and how to solve my problem??
/* asks if the players would like to have another game of Tic Tac Toe */
void prompt_user(int game[][SIZE])
{
char reply;
printf("\nPlay Again? (Y/N): ");
scanf("%c", &reply);
if(reply == 'Y' || reply == 'y')
{
print_empty_board();
initialise_board(game);
}
else if(reply == 'N' || reply == 'n')
{
printf("Hope You Have Enjoyed The Game!\n\n");
exit(0); /* quits the game */
}
}
when using microsoft visual C++ and devC++ to compile and execute, there were no errors in the output when playing the tic-tac-toe game.
however, when i used my school's lab (which is using Linux and xemacs only) pc to compile and execute, the output did not allow me to enter Y or N as an answer to 'Play Again?'. The execution exits immediately. anyone knows the reason and how to solve my problem??
Hello,
I think your bug has to do with the reply definition. You are making two dangerous assumptions with your code... 1) is that char reply; properly initializes the variable (instead of you making an explicit definition, such as reply='s'; so that you know what that variable holds. 2) Your code makes no provision if someone enters in something else, such as the letter 'T' If I were to enter in 'T', neither of your if statements will work, as they fail the tests, and the function will exit without the exit code.
My GUESS is that you might have an extra character coming through the function, and the computer is seeing that as valid input. Granted, the code does not bring in any data except for the one integer, but what is in the character buffer?
Christian
I think your bug has to do with the reply definition. You are making two dangerous assumptions with your code... 1) is that char reply; properly initializes the variable (instead of you making an explicit definition, such as reply='s'; so that you know what that variable holds. 2) Your code makes no provision if someone enters in something else, such as the letter 'T' If I were to enter in 'T', neither of your if statements will work, as they fail the tests, and the function will exit without the exit code.
My GUESS is that you might have an extra character coming through the function, and the computer is seeing that as valid input. Granted, the code does not bring in any data except for the one integer, but what is in the character buffer?
Christian
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
apple bbc cd cellphone computer core deafblind debian dell desktop development enterprise environment fedora game games gentoo google gpl hardware ibm infrastructure install kernel laptop linux marketing microsoft mobile news novell open open source openoffice operating os palm recycling red hat security server source sun system ubuntu unix vista web windows x86
- Can anyone suggest some simple miniproject in C in Linux Environment (Shell Scripting)
- No clue, Need to make a linux server (Linux Servers and Apache)
- needed linux project titles (Community Introductions)
- Linux vs. Microsoft Windows (Linux Users Lounge)
- Linux compilers (C++)
- installation for linux Operating system (*nix Software)
- help with linux on laptop (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Linked List using pointers (C++ ADT)
- Next Thread: merged:nesting loops



Hybrid Mode