Thread: problem exiting program

  1. #16
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Read over the code sample I posted again. the return value needs to be assigned to exit_check, and this will then cause the loop to exit.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    24
    This is what the code is now:

    Code:
    do{
    	printf("---Welcome to Mastmind--- \n");
            printf("Please enter your name: ");
    	fgets(username, 20, stdin);
    	exit_check = continue_playing(username);
    	printf("\nHello %s", username);
            //OTHER CODE IS HERE
    }	while(exit_check == 0);
    
    int continue_playing( char* checkvar )
    {
    	if ((strncmp(checkvar, "EXIT\n", 4) == 0)||(strncmp(checkvar, "exit\n", 4) == 0)||(strncmp(checkvar, "Exit\n", 4) == 0)){
    		return 1;
    	}
    	return 0;
    }
    This is the same as you posted, but this would stop the loop once it gets to the end of the loop, i need it to stop before it gets to the end.

    Thanks

  3. #18
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    You need to check the value of exit_check after the return from continue_playing(), otherwise it's going to continue until it checks it at the end of the do loop, just like I said in my earlier reply.

    Code:
    exit_check = continue_playing(username);
    if (0 != exit_check) 
        break;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem w/ doubles in friend's program
    By mkylman in forum C Programming
    Replies: 16
    Last Post: 11-22-2008, 10:45 AM
  2. Program Termination Problem
    By dacbo in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 02:34 AM
  3. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 02:10 AM
  4. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM