1

The majority of the code is an example from a previous issue on this website but it is irrelevant to my problem (I think). I'm running this program on Windows and want to the program to pause at EOF so I can see everything that has been printed in the command screen rather than it disappearing immediately. Why does printf("Press ENTER key to Continue\n"); getchar(); not pause the command screen when the program ends? (Note system("pause"); works but I know it's only used for Windows which I don't want even though I'm currently on Windows.)

int main() {

    char Password[30];
    char User[5][30];
    int i;
    //char endfile;

    for (i = 0; i < 5; i++) {
        printf("Enter Password");
        scanf("%s", Password);
        strcpy(User[i], Password);
    }

    for (i = 0; i < 5; i++)
        printf("Password %d: %s\n", i + 1, User[i]);

    printf("Press ENTER key to Continue\n");
    //endfile = getchar();  //this did not work either when I tried it
    getchar();

    return 0;
}
Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
blindside044
  • 424
  • 1
  • 5
  • 16
  • 3
    `scanf()` left the newline in the input buffer, ready for `getchar()` to read it without needing more input from the user. See also [Using `fflush(stdin)`](https://stackoverflow.com/questions/2979209/). – Jonathan Leffler Jan 15 '19 at 07:52

0 Answers0