C语言库函数(G类字母)
函数名: getdate
功 能: 取DOS日期
用 法: void getdate(strUCt *dateblk);
程序例:
#include <dos.h>
#include <stdio.h>
int main(void)
{
struct date d;
getdate(&d);
PRintf("The current year is: %d
",
d.da_year);
printf("The current day is: %d
",
d.da_day);
printf("The current month is: %d
",
d.da_mon);
return 0;
}
函数名: getdefaultpalette
功 能: 返回调色板定义结构
用 法: struct palettetype *far getdefaultpalette(void);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
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
",
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
", 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
",
disk);
return 0;
}
函数名: getdrivername
功 能: 返回指向包含当前图形驱动程序名字的字符串指针
用 法: char *getdrivename(void);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
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
",
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
功 能: 取磁盘传输地址
用 法: char far *getdta(void);
程序例:
#include <dos.h>
#include <stdio.h>
int main(void)
{
char far *dta;
dta = getdta();
printf("The current disk transfer
address is: %Fp
", dta);
return 0;
}
函数名: getenv
功 能: 从环境中取字符串
用 法: char *getenv(char *envvar);
程序例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char *s;
s=getenv("COMSPEC"); /* get the comspec environment parameter */
printf("Command processor: %s
",s); /* display comspec parameter */
return 0;
}
函数名: getfat, getfatd
功 能: 取文件分配表信息
用 法: void getfat(int drive, struct fatinfo *fatblkp);
程序例:
#include <stdio.h>
#include <dos.h>
int main(void)
{
struct fatinfo diSKINfo;
int flag = 0;
printf("Please insert disk in drive A
");
getchar();
getfat(1, &diskinfo);
/* get drive information */
printf("
Drive A: is ");
switch((unsigned char) diskinfo.fi_fatid)
{
case 0xFD:
printf("360K low density
");
break;
case 0xF9:
printf("1.2 Meg high density
");
break;
default:
printf("unformatted
");
flag = 1;
}
if (!flag)
{
printf(" sectors per cluster %5d
",
diskinfo.fi_sclus);
printf(" number of clusters %5d
",
diskinfo.fi_nclus);
printf(" bytes per sector %5d
",
diskinfo.fi_bysec);
}
return 0;
&n
补充:软件开发 , C语言 ,