In the beginner tutorial on this site, it mentioned that adding the line getchar(); right before return 0; at the end of the main function would keep the program running until the user hit enter.
Well, this works for me on some programs, and not on others, and I really can't see the difference between them. Following is the main function from a program I wrote based off of one of the tutorial examples. Adding getchar(); doesn't keep the program from closing, either in my program or in the tutorial example (which did not have it included, I added it).
Any help in explaining this would be greatly appreciated.Code:{ ask(); if(age < 0) { printf("You can't have a negative age!\n\n"); ask(); } else if(age > 0 && age < 90) { printf("You are less than 90 years old.\n"); } else { printf("Wow, you're pretty old!\n"); } getchar(); return 0; }



LinkBack URL
About LinkBacks




