getdate(&d); PRintf("The current year is: %d/n", d.da_year); printf("The current day is: %d/n", d.da_day); printf("The current month is: %d/n", d.da_mon); return 0; }
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int i;
/* structure for returning palette copy */ struct palettetype far *pal=(void *) 0;
/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "");
/* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s/n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* terminate with an error code */ exit(1); }
setcolor(getmaxcolor());
/* return a pointer to the default palette */ pal = getdefaultpalette();
for (i=0; i<16; i++) { printf("colors[%d] = %d/n", i, pal->colors[i]); getch(); }
/* clean up */ getch(); closegraph(); return 0; }
函数名: getdisk 功 能: 取当前磁盘驱动器号 用 法: int getdisk(void); 程序例:
#include <stdio.h> #include <dir.h>
int main(void) { int disk;
disk = getdisk() + 'A'; printf("The current drive is: %c/n", disk); return 0; }
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode;
/* stores the device driver name */ char *drivername;
/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "");
/* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s/n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* terminate with an error code */ exit(1); }
setcolor(getmaxcolor());
/* get name of the device driver in use */ drivername = getdrivername();
/* for centering text on the screen */ settextjustify(CENTER_TEXT, CENTER_TEXT);
/* output the name of the driver */ outtextxy(getmaxx() / 2, getmaxy() / 2, drivername);
int main(void) { struct fatinfo diSKINfo; int flag = 0;
printf("Please insert disk in drive A/n"); getchar();
getfat(1, &diskinfo); /* get drive information */
printf("/nDrive A: is "); switch((unsigned char) diskinfo.fi_fatid) { case 0xFD: printf("360K low density/n"); break;
case 0xF9: printf("1.2 Meg high density/n"); break;
default: printf("unformatted/n"); flag = 1; }
if (!flag) { printf(" sectors per cluster %5d/n", diskinfo.fi_sclus); printf(" number of clusters %5d/n", diskinfo.fi_nclus); printf(" bytes per sector %5d/n", diskinfo.fi_bysec); }
return 0; }
函数名: getfillpattern 功 能: 将用户定义的填充模式拷贝到内存中 用 法: void far getfillpattern(char far *upattern); 程序例:
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int maxx, maxy; char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04};
/* 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 */ }
/ the names of the fill styles supported */ char *fname[] = { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL", "LTSLASH_FILL", "SLASH_FILL", "BKSLASH_FILL", "LTBKSLASH_FILL", "HATCH_FILL", "XHATCH_FILL", "INTERLEAVE_FILL", "WIDE_DOT_FILL", "CLOSE_DOT_FILL", "USER_FILL" };
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; struct fillsettingstype fillinfo; int midx, midy; char patstr[40], colstr[40];
/* 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;
/* get information about current fill pattern and color */ getfillsettings(&fillinfo);
/* convert fill information into strings */ sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); sprintf(colstr, "%d is the fill color.", fillinfo.color);
/* display the information */ settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(midx, midy, patstr); outtextxy(midx, midy+2*textheight("W"), colstr);
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int midx, midy, mode; char numname[80], modename[80];
/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "");
/* read result of initialization */ errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s/n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* terminate with an error code */ exit(1); }
midx = getmaxx() / 2; midy = getmaxy() / 2;
/* get mode number and name strings */ mode = getgraphmode(); sprintf(numname, "%d is the current mode number.", mode); sprintf(modename, "%s is the current graphics mode", getmodename(mode));
/* display the information */ settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(midx, midy, numname); outtextxy(midx, midy+2*textheight("W"), modename);