知識社群登入
把主程式和副程式的檔案 分開
by 高顯忠, 2010-11-16 17:28, 人氣(1605)
關鍵是

#include "file.h"



// 這是 主程式的 檔案
#if 0

#endif
// ----------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>

#include "sj-01.h"
// ----------------------------------------------
int main()
{
int i;
for (i=1;i<=20;i++) {
skip(i);
printf("i= %5d, i*i= %5d, sqrt(i)= %10.6lf\n", 
i,      i*i,      sqrt(i));
pause();
}
return 0;
}// end of main()

// 以下,是副程式的檔案

// file: sj-01.h

//   skip(3);
void skip(int no)
{
int i;
// limits no in 1 .. 20
if ((no >= 1) && (no <= 20)) {// no is OK
for (i=1;i<=no;i++) {
// printf("*** in skip(), i= %d\n", i);
printf("\n");
}
}
else {// no is invalid
// printf("*** error in skip(), no= %d\n", no);
printf("\n");
}
}// end of skip()
// ----------------------------------------------

//   pause();
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 extra key- pressed
while (kbhit()) {
getch();
}
}// end of pause()