Hi, I'm a newbie too. Let me try it.

On Sat, 23 Oct 2004 17:35:03 -0700 (PDT)
Kinga Kulesza <[EMAIL PROTECTED]> wrote:

> Hi guys!
>
> I'm totaly new in this group and I'm fresh in C as
> well.
> I have just started C (not C++) and would like to know
> what is the simplest and most efficient way of asking
> the user if he wants to continue (repeat) program or
> simply exit. I have writen (you will laugh) code using
> ineficient goto statement.
> It seems like goto goes to label end executes only
> first encoutered statement. Here is what I came up
> with. Thanks for any feedback.
>
> regards
> Kinga

Emm. which textbook you are reading? IMHO, your code style are rather
old. It looks like from 70'. If you haven't read the flow-control part
of C, go ahead before writting codes.

Pardon my impoliteness. I just want say, some of your code disobey
basic rules of structure language.

> -----------------------------------------------------
> #include <stdio.h>
> main()
Should be
int main( void )
or
int main( int argn, char** argv )  /* if you want to get arguments from shell */

main() is not a C99/ANSI C style, it equals to
int main( int )
It may cause confusion.

Then make your code indent, good to lokk and easy to debug.
> {
>       int c;
> program:
>
>       printf("Do you want to test this program? (y/n) \n");
>       c=getchar();
>       if (c==121)
Dont' use magic numbers, use 'y' or 'n' instead.

>       {
>             printf("THANKS for testing me!!\n");
>             goto program;
>       }
>       else
>             printf("GOODBYE \n");
> }

And don't use goto, it's root of devils. Your code is a typical while
loop:
...
int  c;

printf( "Input your choice, y or n? " );
/* begin the loop */
while( (c = getchar()) == 'y' )
{
      printf( "Thank you to test me! \n" );
      printf( "Input your choice, y or n? " );
}
printf( "good bye\n" );
return 0;
...



To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here
Web Bug from http://us.adserver.yahoo.com/l?M=295196.4901138.6071305.3001176/D=groups/S=:HM/A=2128215/rand=174201822


Yahoo! Groups Links

Reply via email to