Re: restar program
From: Jerry Coffin (jcoffin_at_taeus.com)
Date: 02/07/05
- Next message: Francis Glassborow: "Re: Constructors: Help me answer students question"
- Previous message: richardv2: "Re: Constructors: Help me answer students question"
- In reply to: Carramba: "[C] restar program"
- Next in thread: Anthony Borla: "Re: [C] restar program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Feb 2005 13:54:11 -0800
Carramba wrote:
> hi!
>
> if I have for exemple program
>
> #include <stdio.h>
> main() {
> printf("Enter number:\n");
> scanf("%d", Num);
> printf("Number is %d!\n", Num);
> fflush(stdin);
> getchar();
> }
> how do I start program over so that after printf("Number is %d!\n",
Num);
> I can get line like "press c to continue q to quite" and if c is
> entered so program starts from begining?
Probably a while loop or a do loop, as in:
do {
printf("Enter number:\n");
/* ... */
printf("press c to continue or q to quit");
} while (getchar == 'c');
I know you didn't ask about it, but fflush(stdin) has undefined
behavior. If you'll tell us what you're really trying to accomplish
with it, we may be able to tell you something you can do instead
(though there's no guarantee of it).
--
Later,
Jerry.
The universe is a figment of its own imagination.
- Next message: Francis Glassborow: "Re: Constructors: Help me answer students question"
- Previous message: richardv2: "Re: Constructors: Help me answer students question"
- In reply to: Carramba: "[C] restar program"
- Next in thread: Anthony Borla: "Re: [C] restar program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|