/* get file name */ printf("Enter drive and file name (no path - ie. a:file.dat)/n"); gets(line);
/* put file name in fcb */ if (parsfnm(line, &blk, 1) == NULL) printf("Error in parsfm call/n"); else printf("Drive #%d Name: %11s/n", blk.fcb_drive, blk.fcb_name);
printf("The current status of your keyboard is:/n"); value = peek(0x0040, 0x0017); if (value & 1) printf("Right shift on/n"); else printf("Right shift off/n");
printf("The current status of your keyboard is:/n"); value = peekb(0x0040, 0x0017); if (value & 1) printf("Right shift on/n"); else printf("Right shift off/n");
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int midx, midy; int stangle = 45, endangle = 135, radius = 100;
/* initialize graphics and 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;
/* set fill style and draw a pie slice */ setfillstyle(EMPTY_FILL, getmaxcolor()); pieslice(midx, midy, stangle, endangle, radius);
/* clean up */ getch(); closegraph(); return 0; }
函数名: poke 功 能: 存值到一个给定存储单元 用 法: void poke(int segment, int offset, int value); 程序例:
#include <dos.h> #include <conio.h>
int main(void) { clrscr(); cprintf("Make sure the scroll lock key is off and press any key/r/n"); getch(); poke(0x0000,0x0417,16); cprintf("The scroll lock is now on/r/n"); return 0; }
int main(void) { clrscr(); cprintf("Make sure the scroll lock key is off and press any key/r/n"); getch(); pokeb(0x0000,0x0417,16); cprintf("The scroll lock is now on/r/n"); return 0; }
函数名: poly 功 能: 根据参数产生一个多项式 用 法: double poly(double x, int n, double c[]); 程序例:
int main(void) { /* request autodetection */ int gdriver = DETECT, gmode, errorcode; void *arrow; int x, y, maxx; unsigned int size;
/* initialize graphics and 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 */ }
maxx = getmaxx(); x = 0; y = getmaxy() / 2;
/* draw the image to be grabbed */ draw_arrow(x, y);
/* calculate the size of the image */ size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
/* allocate memory to hold the image */ arrow = malloc(size);
/* grab the image */ getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
/* repeat until a key is pressed */ while (!kbhit()) { /* erase old image */ putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
x += ARROW_SIZE;
if (x >= maxx) x = 0;
/* plot new image */ putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); }
/* clean up */ free(arrow); closegraph(); return 0; }
void draw_arrow(int x, int y) { /* draw an arrow on the screen */ moveto(x, y); linerel(4*ARROW_SIZE, 0); linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); linerel(0, 2*ARROW_SIZE); linerel(2*ARROW_SIZE, -1*ARROW_SIZE); }
函数名: putpixel 功 能: 在指定位置画一像素 用 法: void far putpixel (int x, int y, int pixelcolor); 程序例:
#define PIXEL_COUNT 1000 #define DELAY_TIME 100 /* in milliseconds */
int main(void) { /* request autodetection */ int gdriver = DETECT, gmode, errorcode; int i, x, y, color, maxx, maxy, maxcolor, seed;
/* initialize graphics and 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 */
while (!kbhit()) { /* seed the random number generator */ seed = random(32767); srand(seed); for (i=0; i<PIXEL_COUNT; i++) { x = random(maxx); y = random(maxy); color = random(maxcolor); putpixel(x, y, color); }
delay(DELAY_TIME); srand(seed); for (i=0; i<PIXEL_COUNT; i++) { x = random(maxx); y = random(maxy); color = random(maxcolor); if (color == getpixel(x, y)) putpixel(x, y, 0); } }