cpp 代码
- // file: sj01.h
- void skip(int no);
- void pause(void);
- // ----------------------------------------------
- void skip(int no)
- {
- // limits no in 1 .. 20
- if (!((no >= 1) && (no <= 20))) {
- printf("no is invalid! no= %d\n", no);
- pause();
- no= 1;
- }
- // ----------------------------------------------
- for (int i=1;i<=no;i++) {
- printf("\n");
- }
- }// end skip()
- // ----------------------------------------------
- void pause(void)
- {
- // remove type- ahead
- while (_kbhit()) {
- _getch();
- }
- // ----------------------------------------------
- printf(" Press [Esc] for stop! other key for continue...");
- do {
- // wait for keyPressed
- } while (!_kbhit());
- int ch1= _getch();
- printf("\n");
- // ----------------------------------------------
- if (ch1==0x1b) {
- exit(1);
- }
- // remove other key
- while (_kbhit()) {
- _getch();
- }
- }// end pause()
- // ----------------------------------------------