|
Turbo C 2.0、Borland C++库函数及用例(17) 程序例:#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h>/* names of the various cards supported */ char *dname[] = { "requests detection", "a CGA", "an MCGA", "an EGA", "a 64K EGA", "a monochrome EGA", "an IBM 8514", "a Hercules monochrome", "an AT&T 6300 PC", "a VGA", "an IBM 3270 PC" };int main(void) { /* returns detected hardware info. */ int gdriver, gmode, errorcode; /* detect graphics hardware available */ detectgraph(&gdriver, &gmode); /* read result of detectgraph call */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } /* display the information detected */ clrscr(); printf("You have %s video display \ card.\n", dname[gdriver]); printf("Press any key to halt:"); getch(); return 0; } 函数名: difftime 功 能: 计算两个时刻之间的时间差 用 法: double difftime(time_t time2, time_t time1); 程序例:#include <time.h> #include <stdio.h> #include <dos.h> #include <conio.h>int main(void) { time_t first, second; clrscr(); first = time(NULL); /* Gets system time */ delay(2000); /* Waits 2 secs */ second = time(NULL); /* Gets system time again */ printf("The difference is: %f \ seconds\n",difftime(second,first)); getch(); return 0; } 函数名: disable 功 能: 屏蔽中断 用 法: void disable(void); 程序例:/***NOTE: This is an interrupt service routine. You cannot compile this program with Test Stack Overflow turned on and get an executable file that operates correctly. */#include <stdio.h> #include <dos.h> #include <conio.h>#define INTR 0X1C /* The clock tick interrupt */void interrupt ( *oldhandler)(void);int count=0;void interrupt handler(void) { /* disable interrupts during the handling of
|