C语言库函数大全及应用实例五
函数名: getcurdir
功 能: 取指定驱动器的当前目录
用 法: int getcurdir(int drive, char *direc);
程序例:
#i nclude
#i nclude
#i nclude
char *current_directory(char *path)
{
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
path[0] = ‘A‘ + getdisk(); /* replace X with current drive letter */
getcurdir(0, path+3); /* fill rest of string with current directory */
return(path);
}
int main(void)
{
char curdir[MAXPATH];
current_directory(curdir);
printf("The current directory is %s\n", curdir);
return 0;
}
函数名: getcwd
功 能: 取当前工作目录
用 法: char *getcwd(char *buf, int n);
程序例:
#i nclude
#i nclude
int main(void)
{
char buffer[MAXPATH];
getcwd(buffer, MAXPATH);
printf("The current directory is: %s\n", buffer);
return 0;
}
函数名: getdate
功 能: 取DOS日期
用 法: void getdate(struct *dateblk);
程序例:
#i nclude
#i nclude
int main(void)
{
struct date d;
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;
}
函数名: getdefaultpalette
功 能: 返回调色板定义结构
用 法: struct palettetype *far getdefaultpalette(void);
程序例:
#i nclude
#i nclude
#i nclude
#i nclude
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);
程序例:
#i nclude
#i nclude
int main(void)
{
int disk;
disk = getdisk() + ‘A‘;
printf("The current drive is: %c\n",
disk);
return 0;
}
函数名: getdrivername
功 能: 返回指向包含当前图形驱动程序名字的字符串指针
用 法: char *getdrivename(void);
程序例:
#i nclude
#i nclude
#i nclude
#i nclude
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);
/* clean up */
getch();
closegraph();
return 0;
}
函数名: getdta
#i nclude int main(void)
dta = getdta(); 函数名: getenv #i nclude int main(void) s=getenv("COMSPEC"); /* get the comspec environment parameter */
return 0; 函数名: getfat, getfatd #i nclude int main(void) printf("Please insert disk in drive A\n"); getfat(1, &diskinfo); printf("\nDrive A: is "); case 0xF9: default: if (!flag)
return 0; 函数名: getfillpattern #i nclude int main(void) /* initialize graphics and local variables */ /* read result of initialization */ maxx = getmaxx(); /* select a user defined fill pattern */ /* fill the screen with the pattern */ getch(); /* get the current user defined fill pattern */ /* alter the pattern we grabbed */ /* select our new pattern */ /* fill the screen with the new pattern */
/* clean up */ 函数名: getfillsettings #i nclude / the names of the fill styles supported */ int main(void) /* initialize graphics and local variables */ /* read result of initialization */ midx = getmaxx() / 2; /* get information about current fill pattern and color */ /* convert fill information into strings */ /* display the information */
/* clean up */
#i nclude int main(void)
if ((stream = fopen("TEST.$$$", 函数名: getgraphmode #i nclude int main(void) /* initialize graphics and local variables */ /* read result of initialization */ midx = getmaxx() / 2; /* get mode number and name strings */ /* display the information */
/* clean up */ 函数名: getftime #i nclude int main(void)
if ((stream = fopen("TEST.$$$", 函数名: getgraphmode #i nclude int main(void) /* initialize graphics and local variables */ /* read result of initialization */ midx = getmaxx() / 2; /* get mode number and name strings */ /* display the information */
/* clean up */ 函数名: getimage #i nclude void save_screen(void far *buf[4]); int maxx, maxy; int main(void) /* auto-detect the graphics driver and mode */ /* draw an image on the screen */ save_screen(ptr); /* save the current screen */ closegraph(); void save_screen(void far *buf[4]) yincr = (maxy+1) / 4; for (block=0; block<=3; block++) getimage(0, ystart, maxx, yend, buf[block]); void save_screen(void far *buf[4]) yincr = (maxy+1) / 4; for (block=0; block<=3; block++) getimage(0, ystart, maxx, yend, buf[block]); void restore_screen(void far *buf[4]) yincr = (maxy+1) / 4;
for (block=0; block<=3; block++)
功 能: 取磁盘传输地址
用 法: char far *getdta(void);
程序例:
#i nclude
{
char far *dta;
printf("The current disk transfer \
address is: %Fp\n", dta);
return 0;
}
功 能: 从环境中取字符串
用 法: char *getenv(char *envvar);
程序例:
#i nclude
{
char *s;
printf("Command processor: %s\n",s); /* display comspec parameter */
}
功 能: 取文件分配表信息
用 法: void getfat(int drive, struct fatinfo *fatblkp);
程序例:
#i nclude
{
struct fatinfo diskinfo;
int flag = 0;
getchar();
/* get drive information */
switch((unsigned char) diskinfo.fi_fatid)
{
case 0xFD:
printf("360K low density\n");
break;
printf("1.2 Meg high density\n");
break;
printf("unformatted\n");
flag = 1;
}
{
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);
}
}
功 能: 将用户定义的填充模式拷贝到内存中
用 法: void far getfillpattern(char far *upattern);
程序例:
#i nclude
#i nclude
#i nclude
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04};
initgraph(&gdriver, &gmode, "");
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 */
}
maxy = getmaxy();
setcolor(getmaxcolor());
setfillpattern(pattern, getmaxcolor());
bar(0, 0, maxx, maxy);
getfillpattern(pattern);
pattern[4] -= 1;
pattern[5] -= 3;
pattern[6] += 3;
pattern[7] -= 4;
setfillpattern(pattern, getmaxcolor());
bar(0, 0, maxx, maxy);
getch();
closegraph();
return 0;
}
功 能: 取得有关当前填充模式和填充颜色的信息
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
程序例:
#i nclude
#i nclude
#i nclude
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"
};
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
struct fillsettingstype fillinfo;
int midx, midy;
char patstr[40], colstr[40];
initgraph(&gdriver, &gmode, "");
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 */
}
midy = getmaxy() / 2;
getfillsettings(&fillinfo);
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
sprintf(colstr, "%d is the fill color.", fillinfo.color);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy, patstr);
outtextxy(midx, midy+2*textheight("W"), colstr);
getch();
closegraph();
return 0;
}
函数名: getftime
功 能: 取文件日期和时间
用 法: int getftime(int handle, struct ftime *ftimep);
程序例:
#i nclude
{
FILE *stream;
struct ftime ft;
"wt")) == NULL)
{
fprintf(stderr,
"Cannot open output file.\n");
return 1;
}
getftime(fileno(stream), &ft);
printf("File time: %u:%u:%u\n",
ft.ft_hour, ft.ft_min,
ft.ft_tsec * 2);
printf("File date: %u/%u/%u\n",
ft.ft_month, ft.ft_day,
ft.ft_year+1980);
fclose(stream);
return 0;
}
功 能: 返回当前图形模式
用 法: int far getgraphmode(void);
程序例:
#i nclude
#i nclude
#i nclude
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, mode;
char numname[80], modename[80];
initgraph(&gdriver, &gmode, "");
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);
}
midy = getmaxy() / 2;
mode = getgraphmode();
sprintf(numname,
"%d is the current mode number.",
mode);
sprintf(modename,
"%s is the current graphics mode",
getmodename(mode));
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy, numname);
outtextxy(midx, midy+2*textheight("W"),
modename);
getch();
closegraph();
return 0;
}
功 能: 取文件日期和时间
用 法: int getftime(int handle, struct ftime *ftimep);
程序例:
#i nclude
{
FILE *stream;
struct ftime ft;
"wt")) == NULL)
{
fprintf(stderr,
"Cannot open output file.\n");
return 1;
}
getftime(fileno(stream), &ft);
printf("File time: %u:%u:%u\n",
ft.ft_hour, ft.ft_min,
ft.ft_tsec * 2);
printf("File date: %u/%u/%u\n",
ft.ft_month, ft.ft_day,
ft.ft_year+1980);
fclose(stream);
return 0;
}
功 能: 返回当前图形模式
用 法: int far getgraphmode(void);
程序例:
#i nclude
#i nclude
#i nclude
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, mode;
char numname[80], modename[80];
initgraph(&gdriver, &gmode, "");
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);
}
midy = getmaxy() / 2;
mode = getgraphmode();
sprintf(numname,
"%d is the current mode number.",
mode);
sprintf(modename,
"%s is the current graphics mode",
getmodename(mode));
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy, numname);
outtextxy(midx, midy+2*textheight("W"),
modename);
getch();
closegraph();
return 0;
}
功 能: 将指定区域的一个位图存到主存中
用 法: void far getimage(int left, int top, int right, int bottom,
void far *bitmap);
程序例:
#i nclude
#i nclude
#i nclude
#i nclude
void restore_screen(void far *buf[4]);
{
int gdriver=DETECT, gmode, errorcode;
void far *ptr[4];
initgraph(&gdriver, &gmode, "");
errorcode = graphresult(); /* check for any errors */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();
rectangle(0, 0, maxx, maxy);
line(0, 0, maxx, maxy);
line(0, maxy, maxx, 0);
getch(); /* pause screen */
cleardevice(); /* clear screen */
restore_screen(ptr); /* restore the screen */
getch(); /* pause screen */
return 0;
}
{
unsigned size;
int ystart=0, yend, yincr, block;
yend = yincr;
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */
{
if ((buf[block] = farmalloc(size)) == NULL)
{
closegraph();
printf("Error: not enough heap space in save_screen().\n");
exit(1);
}
ystart = yend + 1;
yend += yincr + 1;
}
}
{
unsigned size;
int ystart=0, yend, yincr, block;
yend = yincr;
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */
{
if ((buf[block] = farmalloc(size)) == NULL)
{
closegraph();
printf("Error: not enough heap space in save_screen().\n");
exit(1);
}
ystart = yend + 1;
yend += yincr + 1;
}
}
{
int ystart=0, yend, yincr, block;
yend = yincr;
{
putimage(0, ystart, buf[block], COPY_PUT);
farfree(buf[block]);
ystart = yend + 1;
yend += yincr + 1;
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。