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.
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"
This is what the code is now:
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.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; }
Thanks
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;