⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 4 页
字号:
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); 
} </PRE>
<PRE>setcolor(getmaxcolor()); </PRE>
<PRE>/* get name of the device driver in use */ 
drivername = getdrivername(); </PRE>
<PRE>/* for centering text on the screen */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* output the name of the driver */ 
outtextxy(getmaxx() / 2, getmaxy() / 2, 
drivername); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getdta </font>
功 能: 取磁盘传输地址 
用 法: char far *getdta(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char far *dta; </PRE>
<PRE>dta = getdta(); 
printf(&quot;The current disk transfer \ 
address is: %Fp\n&quot;, dta); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getenv </font>
功 能: 从环境中取字符串 
用 法: char *getenv(char *envvar); 
程序例: </PRE>
<PRE>#include 
#include 
</PRE>
<PRE>int main(void) 
{ 
char *s; </PRE>
<PRE>s=getenv(&quot;COMSPEC&quot;); /* get the comspec environment parameter */ 
printf(&quot;Command processor: %s\n&quot;,s); /* display comspec parameter */ </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> getfat, getfatd </font>
功 能: 取文件分配表信息 
用 法: void getfat(int drive, struct fatinfo *fatblkp); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
struct fatinfo diskinfo; 
int flag = 0; </PRE>
<PRE>printf(&quot;Please insert disk in drive A\n&quot;); 
getchar(); </PRE>
<PRE>getfat(1, &amp;diskinfo); 
/* get drive information */ </PRE>
<PRE>printf(&quot;\nDrive A: is &quot;); 
switch((unsigned char) diskinfo.fi_fatid) 
{ 
case 0xFD: 
printf(&quot;360K low density\n&quot;); 
break; </PRE>
<PRE>case 0xF9: 
printf(&quot;1.2 Meg high density\n&quot;); 
break; </PRE>
<PRE>default: 
printf(&quot;unformatted\n&quot;); 
flag = 1; 
} </PRE>
<PRE>if (!flag) 
{ 
printf(&quot; sectors per cluster %5d\n&quot;, 
diskinfo.fi_sclus); 
printf(&quot; number of clusters %5d\n&quot;, 
diskinfo.fi_nclus); 
printf(&quot; bytes per sector %5d\n&quot;, 
diskinfo.fi_bysec); 
} </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getfillpattern </font>
功 能: 将用户定义的填充模式拷贝到内存中 
用 法: void far getfillpattern(char far *upattern); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>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}; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>maxx = getmaxx(); 
maxy = getmaxy(); 
setcolor(getmaxcolor()); </PRE>
<PRE>/* select a user defined fill pattern */ 
setfillpattern(pattern, getmaxcolor()); </PRE>
<PRE>/* fill the screen with the pattern */ 
bar(0, 0, maxx, maxy); </PRE>
<PRE>getch(); </PRE>
<PRE>/* get the current user defined fill pattern */ 
getfillpattern(pattern); </PRE>
<PRE>/* alter the pattern we grabbed */ 
pattern[4] -= 1; 
pattern[5] -= 3; 
pattern[6] += 3; 
pattern[7] -= 4; </PRE>
<PRE>/* select our new pattern */ 
setfillpattern(pattern, getmaxcolor()); </PRE>
<PRE>/* fill the screen with the new pattern */ 
bar(0, 0, maxx, maxy); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getfillsettings </font>
功 能: 取得有关当前填充模式和填充颜色的信息 
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>/ the names of the fill styles supported */ 
char *fname[] = { &quot;EMPTY_FILL&quot;, 
&quot;SOLID_FILL&quot;, 
&quot;LINE_FILL&quot;, 
&quot;LTSLASH_FILL&quot;, 
&quot;SLASH_FILL&quot;, 
&quot;BKSLASH_FILL&quot;, 
&quot;LTBKSLASH_FILL&quot;, 
&quot;HATCH_FILL&quot;, 
&quot;XHATCH_FILL&quot;, 
&quot;INTERLEAVE_FILL&quot;, 
&quot;WIDE_DOT_FILL&quot;, 
&quot;CLOSE_DOT_FILL&quot;, 
&quot;USER_FILL&quot; 
}; </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
struct fillsettingstype fillinfo; 
int midx, midy; 
char patstr[40], colstr[40]; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>midx = getmaxx() / 2; 
midy = getmaxy() / 2; </PRE>
<PRE>/* get information about current fill pattern and color */ 
getfillsettings(&amp;fillinfo); </PRE>
<PRE>/* convert fill information into strings */ 
sprintf(patstr, &quot;%s is the fill style.&quot;, fname[fillinfo.pattern]); 
sprintf(colstr, &quot;%d is the fill color.&quot;, fillinfo.color); </PRE>
<PRE>/* display the information */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(midx, midy, patstr); 
outtextxy(midx, midy+2*textheight(&quot;W&quot;), colstr); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getftime </font>
功 能: 取文件日期和时间 
用 法: int getftime(int handle, struct ftime *ftimep); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
FILE *stream; 
struct ftime ft; </PRE>
<PRE>if ((stream = fopen(&quot;TEST.$$$&quot;, 
&quot;wt&quot;)) == NULL) 
{ 
fprintf(stderr, 
&quot;Cannot open output file.\n&quot;); 
return 1; 
} 
getftime(fileno(stream), &amp;ft); 
printf(&quot;File time: %u:%u:%u\n&quot;, 
ft.ft_hour, ft.ft_min, 
ft.ft_tsec * 2); 
printf(&quot;File date: %u/%u/%u\n&quot;, 
ft.ft_month, ft.ft_day, 
ft.ft_year+1980); 
fclose(stream); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getgraphmode </font>
功 能: 返回当前图形模式 
用 法: int far getgraphmode(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy, mode; 
char numname[80], modename[80]; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
/* an error occurred */ 
if (errorcode != grOk) 
{ 
printf(&quot;Graphics error: %s\n&quot;, 
grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
/* terminate with an error code */ 
exit(1); 
} </PRE>
<PRE>midx = getmaxx() / 2; 
midy = getmaxy() / 2; </PRE>
<PRE>/* get mode number and name strings */ 
mode = getgraphmode(); 
sprintf(numname, 
&quot;%d is the current mode number.&quot;, 
mode); 
sprintf(modename, 
&quot;%s is the current graphics mode&quot;, 
getmodename(mode)); </PRE>
<PRE>/* display the information */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(midx, midy, numname); 
outtextxy(midx, midy+2*textheight(&quot;W&quot;), 
modename); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getftime </font>
功 能: 取文件日期和时间 
用 法: int getftime(int handle, struct ftime *ftimep); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
FILE *stream; 
struct ftime ft; </PRE>
<PRE>if ((stream = fopen(&quot;TEST.$$$&quot;, 
&quot;wt&quot;)) == NULL) 
{ 
fprintf(stderr, 
&quot;Cannot open output file.\n&quot;); 
return 1; 
} 
getftime(fileno(stream), &amp;ft); 
printf(&quot;File time: %u:%u:%u\n&quot;, 
ft.ft_hour, ft.ft_min, 
ft.ft_tsec * 2); 
printf(&quot;File date: %u/%u/%u\n&quot;, 
ft.ft_month, ft.ft_day, 
ft.ft_year+1980); 
fclose(stream); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getgraphmode </font>
功 能: 返回当前图形模式 
用 法: int far getgraphmode(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy, mode; 
char numname[80], modename[80]; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
/* an error occurred */ 
if (errorcode != grOk) 
{ 
printf(&quot;Graphics error: %s\n&quot;, 
grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
/* terminate with an error code */ 
exit(1); 
} </PRE>
<PRE>midx = getmaxx() / 2; 
midy = getmaxy() / 2; </PRE>
<PRE>/* get mode number and name strings */ 
mode = getgraphmode(); 
sprintf(numname, 
&quot;%d is the current mode number.&quot;, 
mode); 
sprintf(modename, 
&quot;%s is the current graphics mode&quot;, 
getmodename(mode)); </PRE>
<PRE>/* display the information */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(midx, midy, numname); 
outtextxy(midx, midy+2*textheight(&quot;W&quot;), 
modename); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getimage </font>
功 能: 将指定区域的一个位图存到主存中 
用 法: void far getimage(int left, int top, int right, int bottom, 
void far *bitmap); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>void save_screen(void far *buf[4]); 
void restore_screen(void far *buf[4]); </PRE>
<PRE>int maxx, maxy; </PRE>
<PRE>int main(void) 
{ 
int gdriver=DETECT, gmode, errorcode; 
void far *ptr[4]; </PRE>
<PRE>/* auto-detect the graphics driver and mode */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); 
errorcode = graphresult(); /* check for any errors */ 
if (errorcode != grOk) 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); 
} 
maxx = getmaxx(); 
maxy = getmaxy(); </PRE>
<PRE>/* draw an image on the screen */ 
rectangle(0, 0, maxx, maxy); 
line(0, 0, maxx, maxy); 
line(0, maxy, maxx, 0); </PRE>
<PRE>save_screen(ptr); /* save the current screen */ 
getch(); /* pause screen */ 
cleardevice(); /* clear screen */ 
restore_screen(ptr); /* restore the screen */ 
getch(); /* pause screen */ </PRE>
<PRE>closegraph(); 
return 0; 
} </PRE>
<PRE>void save_screen(void far *buf[4]) 
{ 
unsigned size; 
int ystart=0, yend, yincr, block; </PRE>
<PRE>yincr = (maxy+1) / 4; 
yend = yincr; 
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </PRE>
<PRE>for (block=0; block&lt;=3; block++) 
{ 
if ((buf[block] = farmalloc(size)) == NULL) 
{ 
closegraph(); 
printf(&quot;Error: not enough heap space in save_screen().\n&quot;); 
exit(1); 
} </PRE>
<PRE>getimage(0, ystart, maxx, yend, buf[block]); 
ystart = yend + 1; 
yend += yincr + 1; 
} 
} </PRE>
<PRE>void save_screen(void far *buf[4]) 
{ 
unsigned size; 
int ystart=0, yend, yincr, block; </PRE>
<PRE>yincr = (maxy+1) / 4; 
yend = yincr; 
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </PRE>
<PRE>for (block=0; block&lt;=3; block++) 
{ 
if ((buf[block] = farmalloc(size)) == NULL) 
{ 
closegraph(); 
printf(&quot;Error: not enough heap space in save_screen().\n&quot;); 
exit(1); 
} </PRE>
<PRE>getimage(0, ystart, maxx, yend, buf[block]); 
ystart = yend + 1; 
yend += yincr + 1; 
} 
} </PRE>
<PRE>void restore_screen(void far *buf[4]) 
{ 
int ystart=0, yend, yincr, block; </PRE>
<PRE>yincr = (maxy+1) / 4; 
yend = yincr; </PRE>
<PRE>for (block=0; block&lt;=3; block++) 
{ 
putimage(0, ystart, buf[block], COPY_PUT); 
farfree(buf[block]); 
ystart = yend + 1; 
yend += yincr + 1; 
} 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getlinesettings</font> 
功 能: 取当前线型、模式和宽度 
用 法: void far getlinesettings(struct linesettingstype far *lininfo): 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>/* the names of the line styles supported */ 
char *lname[] = { &quot;SOLID_LINE&quot;, 
&quot;DOTTED_LINE&quot;, 
&quot;CENTER_LINE&quot;, 
&quot;DASHED_LINE&quot;, 
&quot;USERBIT_LINE&quot; 
}; </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
struct linesettingstype lineinfo; 
int midx, midy; 
char lstyle[80], lpattern[80], lwidth[80]; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>midx = getmaxx() / 2; 
midy = getmaxy() / 2; </PRE>
<PRE>/* get information about current line settings */ 
getlinesettings(&amp;lineinfo); </PRE>
<PRE>/* convert line information into strings */ 
sprintf(lstyle, &quot;%s is the line style.&quot;, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -