許多經典 C 語言教學書使用 Turbo C (TC) 開發,但現代環境多為 VC++ 6.0 或更新版本。直接編譯會遇到標頭檔找不到、函式庫不相容等問題。
TC 包含許多非標準 C 函式,如 dos.h、conio.h、graphics.h,這些在 VC++ 6.0 中不存在或行為不同。
| TC 函式 | 標頭檔 | VC++ 6.0 替代方案 | 標頭檔 |
|---|---|---|---|
| clrscr() | conio.h | system("cls") | stdlib.h |
| getch() | conio.h | _getch() | conio.h |
| gotoxy(x,y) | conio.h | SetConsoleCursorPosition() | windows.h |
| delay(ms) | dos.h | Sleep(ms) | windows.h |
| randomize() | stdlib.h | srand(time(NULL)) | time.h, stdlib.h |
| random(n) | stdlib.h | rand() % n | stdlib.h |
| textbackground() | conio.h | SetConsoleTextAttribute() | windows.h |
TC 的 graphics.h (BGI) 在 VC++ 無對應。建議方案:
// TC: 取得系統時間
struct time t;
gettime(&t);
// VC++ 6.0 替代方案
#include <time.h>
time_t now = time(NULL);
struct tm *t = localtime(&now);
int hour = t->tm_hour;
int min = t->tm_min;
int sec = t->tm_sec;
far、near、huge 關鍵字VC++ 6.0 已停止維護超過 20 年。建議新專案使用:
理解編譯器差異,掌握標準 C 與平台擴充的界線,是移植舊專案的關鍵。