NO

Author Topic: Press Any Key To Continue...  (Read 11526 times)

lordvoo

  • Guest
Press Any Key To Continue...
« on: February 05, 2013, 08:16:53 PM »
Hi,
I am new to programming and currently working on a project for my intro to programming class. I am trying to get a "Press any key to continue..." prompt but so far have only been able to get it to do so if you input an actual character. I do not want to use system("PAUSE") tho I know that would work. Any way to replicate the system("PAUSE") without actually using it?

Thanks,

Here is what I have thus far:

Code: [Select]
}
printf("\n Do you want to perform another calculation? (y/n)> \n\n");
while((c = getchar()) != '\n' && c != EOF);
scanf(" %c",&again);
{
if(again != 'y' || again != 'Y' || again != 'n' || again !='N'){
printf("\n\n#######Invalid Selection #######\n\n");
printf("(Error)\n\n");
}
else{
break;
}
while((getchar() == EOF));
printf("\nPess any key to continue...\n");
scanf(" %c",&id);


}

}
while (again == 'y' || again == 'Y');
return(0);
}

Offline jcfuller

  • Member
  • *
  • Posts: 36
Re: Press Any Key To Continue...
« Reply #1 on: February 05, 2013, 08:21:19 PM »
This is what I use for Pause:

Code: [Select]
void Pause(void)
{
  printf("\n%s\n","Press any key to continue . . .");
  _getch();
}


James

Tino

  • Guest
Re: Press Any Key To Continue...
« Reply #2 on: February 06, 2013, 03:22:34 AM »

migf1

  • Guest
Re: Press Any Key To Continue...
« Reply #3 on: February 06, 2013, 11:30:10 AM »
You may try the following, cross-platform macro...

Code: [Select]
/* cross-platform alternative to Windows system("pause") */
#define pressENTER()  \
do{ \
    int mYcHAr; \
    printf( "Press ENTER to continue..." );  \
    fflush(stdout); \
    while ( (mYcHAr=getchar()) != '\n' && EOF != mYcHAr ) \
        ;  \
}while(0)