|
Turbo C 2.0、Borland C++库函数及用例(21) int gdriver = DETECT, gmode, errorcode; int midx, midy; int stangle = 0, endangle = 360; int xradius = 100, yradius = 50; /* initialize graphics, local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ 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 */ } midx = getmaxx() / 2; midy = getmaxy() / 2; setcolor(getmaxcolor()); /* draw ellipse */ ellipse(midx, midy, stangle, endangle, xradius, yradius); /* clean up */ getch(); closegraph(); return 0; } 函数名: enable 功 能: 开放硬件中断 用 法: void enable(void); 程序例:/* ** NOTE: This is an interrupt service routine. You can NOT compile this program with Test Stack Overflow turned on and get an executable file which will operate correctly. */#include <stdio.h> #include <dos.h> #include <conio.h>/* The clock tick interrupt */ #define INTR 0X1Cvoid interrupt ( *oldhandler)(void);int count=0;void interrupt handler(void) { /* disable interrupts during the handling of the interrupt */ disable(); /* increase the global counter */ count++; /* re enable interrupts at the end of the handler*/ enable(); /* call the old routine */ oldhandler(); }int main(void) { /* save the old interrupt vector */ oldhandler = getvect(INTR); /* install the new interrupt handler */ setvect(INTR, handler);/* loop until the counter exceeds 20 */ while (count < 20) printf("count is %d\n",count);/* reset the old interrupt handler */ setvect(INTR, oldhandler); return 0; } 函数名: eof 功 能: 检测文件结束 用 法: int eof(int *handle); 程序例:#include <sys\stat.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include <io.h>int main(void) {
|