(C) back or continue
From: Paul Fedorenko (pfedorenko_at_look.ca)
Date: 10/28/04
- Next message: nss: "Re: Need help with C declaration confusion"
- Previous message: someone_at_somedomain.com.invalid: "Re: conio.h kbhit() and getch()"
- Next in thread: Paul Fedorenko: "Re: (C) back or continue"
- Reply: Paul Fedorenko: "Re: (C) back or continue"
- Reply: Adrian: "Re: (C) back or continue"
- Reply: Chris: "Re: (C) back or continue"
- Reply: Karl Heinz Buchegger: "Re: (C) back or continue"
- Reply: Paul Fedorenko: "Re: (C) back or continue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 28 Oct 2004 00:11:56 -0400
A friend of mine asked me to write a text-based "game" for him as part of a
psyche experiment that he's going to be conducting. The first few screens
of the program are supposed to display the instructions for gameplay, and
consist of a lot of printf() statements.
What I'm trying to do is figure out a way of allowing the user to go back a
screen to double-check instructions if they missed something, then continue
on to the next screen. I've written the program so that each screen of
instructions lives in it's own function, and going back a screen is simply a
matter of calling the function that came before...
Like this, I guess:
void screen_2(void)
{
printf("Press <Enter> to continue or <b> to go back. ");
getchar(option);
// or possibly scanf("%c", &option);
if (option = 'b')
screen_1(); // goes back to previous screen
else
// expression to return to main() so next function can be run
}
The problem, as you can see, is trying to figure out what comes after that
else. I've tried a "return 0;" but that causes the program exit to the last
couple of lines of main(); and skipping what I want it to do altogether.
Here's a sample of what I have in main(); just for reference:
void screen_2(void);
int main(void)
{
char again;
do
{
screen_1();
screen_2();
printf("\n\nPlay again (Y/N)? ");
scanf("%c", &again);
}
while(again != 'N' && again != 'n');
// system("cls");
printf("Thank you for playing.");
return 0;
}
I'm going to keep working on it, and the rest of the program (have to build
an array, and set up some file I/O), and I'll check back here tomorrow or
something.
- Next message: nss: "Re: Need help with C declaration confusion"
- Previous message: someone_at_somedomain.com.invalid: "Re: conio.h kbhit() and getch()"
- Next in thread: Paul Fedorenko: "Re: (C) back or continue"
- Reply: Paul Fedorenko: "Re: (C) back or continue"
- Reply: Adrian: "Re: (C) back or continue"
- Reply: Chris: "Re: (C) back or continue"
- Reply: Karl Heinz Buchegger: "Re: (C) back or continue"
- Reply: Paul Fedorenko: "Re: (C) back or continue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|