Thread: How to repeat program in C

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    8

    Question How to repeat program in C

    Well, i have a problem. i'm interested that is it possible to repeat a program with command goto or some other order i C ?
    For example
    Code:
    main()
    {
    
    
    
    .....some code...
    
    i want from here to display do you want to repeat (y/n)
    an after they press y to go to begining of code a do the code again
    }
    I would be gratefull for any help.
    It would be best if someone provide code and not just explenation
    Thank you wery much !

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by i6472 View Post
    It would be best if someone provide code and not just explenation
    Of course. Spoonfeeding is always more desirable than requiring you to solve a problem.

    For the looping part, look up the "while" loop.

    For the writing and reading part, look up "input and output".
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    #include <stdio.h>
    
    int main() {
    	char buffer[666] = {0};
    
    	while (buffer[0] != 'n') {
    		printf("do you want to repeat (y/n) ");
    		fgets(buffer, 666, stdin);
    	}
    
    	return 0;
    }


    Quote Originally Posted by grumpy View Post
    Of course. Spoonfeeding is always more desirable than requiring you to solve a problem.
    There's nothing wrong with asking for example code. One of the worst trends in documentation is the sort which prattles incoherently on for pages without managing to demonstrate anything concrete.

    Unless someone has to make little choo-choo train noises to get the OP to open his/her mouth. Then it's spoonfeeding.

    Quote Originally Posted by i6472 View Post
    Well, i have a problem. i'm interested that is it possible to repeat a program with command goto or some other order i C ?
    Kind of amazing you know this word "goto" but seem completely unaware of "loops". You had a VIC20 or something back in the day didn't you?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM