In my simple program, when it executes the getchar method execute before printf method.
Why this happen and how to solve this??
#include <stdio.h>
#include <stdlib.h>
#define SUCCESS 0
void exit_Pro()
{
printf("Press any Key to exit: ");
fflush(stdin);
getchar();
}
int main(int argc, char **argv) {
atexit(exit_Pro);
return SUCCESS;
}
Platform: Window 7
Compiler(IDE): Eclipse CDT
First of all, I agree with nonsensical:
fflush(stdin)is a bad thing to do. Here’s further explanation. (And if 9 experienced programmers all told me that I was doing something wrong, I’d believe them.)Now, to try and help you debug your code, can you tell us whether this simplified code exhibits the same problem on your system?