Re: restar program

From: Jerry Coffin (jcoffin_at_taeus.com)
Date: 02/07/05


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.


Relevant Pages

  • How to make loop month by month ?
    ... i'm begining with Visual Basic Express Edition and i try ... to make a loop month by month between two dates. ... Estelle (from Paris) ...
    (microsoft.public.dotnet.languages.vb)
  • Clearing multiple variables
    ... I have a lot of variables in the begining of a function call that I need to ... I would like to be able to do a loop to ... clear these variables, Data1 through Data47, without doing it in a long list ...
    (microsoft.public.vb.controls)
  • Re: Looking similar command in Access
    ... S> FoxPro support EXIT and LOOP command, EXIT kick you out from the entire ... S> loop and LOOP take you back at begining of the loop and ignores command ... S> in the loop after the LOOP command. ...
    (microsoft.public.fox.helpwanted)
  • Re: [C] restar program
    ... >if I have for exemple program ... fflush is only defined for output ... streams. ... >so program starts from begining? ...
    (alt.comp.lang.learn.c-cpp)