I am doing a team project with some people that prefer Linux and some people prefer Windows. We are also not allowed to share code for security reasons. One thing the Windows people love to whine about is a way to hold the window open. So the way they usually solve the problem is with:
#include <conio.h>
getch();
This creates a problem for the Linux users since we do not have that library. I have been looking for ways to solve this problem and I really like this idea.
#include <stdlib.h> //For system commands
//Detect and define which command to use
#ifndef WIN32
#define COMMAND "clear" //Clears a linux console screen
#else
#define COMMAND "cls" //Clears a windows console screen
#endif
#define wipe() system( COMMAND )
//To clear the console screen use wipe();
#define wait() {printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);}
//To pause the program or hold the console screen open use wait();
This seems to work when I use #defines but not when I just use this line:
printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);
Since I know most of the programmers pretty well I know they use scanf so I added this and it worked:
while ((getchar()) != '\n');
Why did the #defines work without the extra while loop, but I needed the extra while loop when not using the #defines? Do #defines behave a little different? I can not look at the others peoples code unfortunately. Is there a better way to solve the problem of holding the window open for Windows people but not screwing up the Linux people?