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

📄 g.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body bgcolor="#00FFFF" text="#000080">

<PRE><font size="5"><a href="a.htm">A</a> <a href="b.htm">B</a> <a href="c.htm">C</a> <a href="d.htm">D</a> <a href="e.htm">E</a> <a href="f.htm">F</a> <a href="g.htm">G</a> <a href="h.htm">H</a> <a href="i.htm">I</a> <a href="k.htm">K</a> <a href="l.htm">L</a> <a href="m.htm">M</a> <a href="n.htm">N</a> <a href="o.htm">O</a> <a href="p.htm">P</a> <a href="q.htm">Q</a> <a href="r.htm">R</a> <a href="s.htm">S</a> <a href="t.htm">T</a> <a href="u.htm">U</a> <a href="v.htm">V</a> <a href="w.htm">W</a> </font></PRE>

<PRE> </PRE>

<PRE>函数大全(g开头)

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">gcvt </font>
功 能: 把浮点数转换成字符串 
用 法: char *gcvt(double value, int ndigit, char *buf); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char str[25]; 
double num; 
int sig = 5; /* significant digits */ </PRE>
<PRE>/* a regular number */ 
num = 9.876; 
gcvt(num, sig, str); 
printf(&quot;string = %s\n&quot;, str); </PRE>
<PRE>/* a negative number */ 
num = -123.4567; 
gcvt(num, sig, str); 
printf(&quot;string = %s\n&quot;, str); </PRE>
<PRE>/* scientific notation */ 
num = 0.678e5; 
gcvt(num, sig, str); 
printf(&quot;string = %s\n&quot;, str); </PRE>
<PRE>return(0); 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">geninterrupt </font>
功 能: 产生一个软中断 
用 法: void geninterrupt(int intr_num); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>/* function prototype */ 
void writechar(char ch); </PRE>
<PRE>int main(void) 
{ 
clrscr(); 
gotoxy(80,25); 
writechar('*'); 
getch(); 
return 0; 
} </PRE>
<PRE>/* 
outputs a character at the current cursor 
position using the video BIOS to avoid the 
scrolling of the screen when writing to 
location (80,25). 
*/ </PRE>
<PRE>void writechar(char ch) 
{ 
struct text_info ti; 
/* grab current text settings */ 
gettextinfo(&amp;ti); 
/* interrupt 0x10 sub-function 9 */ 
_AH = 9; 
/* character to be output */ 
_AL = ch; 
_BH = 0; /* video page */ 
_BL = ti.attribute; /* video attribute */ 
_CX = 1; /* repetition factor */ 
geninterrupt(0x10); /* output the char */ 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getarccoords</font> 
功 能: 取得最后一次调用arc的坐标 
用 法: void far getarccoords(struct arccoordstype far *arccoords); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
struct arccoordstype arcinfo; 
int midx, midy; 
int stangle = 45, endangle = 270; 
char sstr[80], estr[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>/* draw arc and get coordinates */ 
setcolor(getmaxcolor()); 
arc(midx, midy, stangle, endangle, 100); 
getarccoords(&amp;arcinfo); </PRE>
<PRE>/* convert arc information into strings */ 
sprintf(sstr, &quot;*- (%d, %d)&quot;, 
arcinfo.xstart, arcinfo.ystart); 
sprintf(estr, &quot;*- (%d, %d)&quot;, 
arcinfo.xend, arcinfo.yend); </PRE>
<PRE>/* output the arc information */ 
outtextxy(arcinfo.xstart, 
arcinfo.ystart, sstr); 
outtextxy(arcinfo.xend, 
arcinfo.yend, estr); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> getaspectratio </font>
功 能: 返回当前图形模式的纵横比 
用 法: void far getaspectratio(int far *xasp, int far *yasp); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int xasp, yasp, midx, midy; </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; 
setcolor(getmaxcolor()); </PRE>
<PRE>/* get current aspect ratio settings */ 
getaspectratio(&amp;xasp, &amp;yasp); </PRE>
<PRE>/* draw normal circle */ 
circle(midx, midy, 100); 
getch(); </PRE>
<PRE>/* draw wide circle */ 
cleardevice(); 
setaspectratio(xasp/2, yasp); 
circle(midx, midy, 100); 
getch(); </PRE>
<PRE>/* draw narrow circle */ 
cleardevice(); 
setaspectratio(xasp, yasp/2); 
circle(midx, midy, 100); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getbkcolor </font>
功 能: 返回当前背景颜色 
用 法: int far getbkcolor(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int bkcolor, midx, midy; 
char bkname[35]; </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; 
setcolor(getmaxcolor()); </PRE>
<PRE>/* for centering text on the display */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* get the current background color */ 
bkcolor = getbkcolor(); </PRE>
<PRE>/* convert color value into a string */ 
itoa(bkcolor, bkname, 10); 
strcat(bkname, 
&quot; is the current background color.&quot;); </PRE>
<PRE>/* display a message */ 
outtextxy(midx, midy, bkname); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getc </font>
功 能: 从流中取字符 
用 法: int getc(FILE *stream); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void) 
{ 
char ch; </PRE>
<PRE>printf(&quot;Input a character:&quot;); 
/* read a character from the 
standard input stream */ 
ch = getc(stdin); 
printf(&quot;The character input was: '%c'\n&quot;, 
ch); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getcbrk </font>
功 能: 获取Control_break设置 
用 法: int getcbrk(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
if (getcbrk()) 
printf(&quot;Cntrl-brk flag is on\n&quot;); 
else 
printf(&quot;Cntrl-brk flag is off\n&quot;); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> getch </font>
功 能: 从控制台无回显地取一个字符 
用 法: int getch(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char ch; </PRE>
<PRE>printf(&quot;Input a character:&quot;); 
ch = getche(); 
printf(&quot;\nYou input a '%c'\n&quot;, ch); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> getchar </font>
功 能: 从stdin流中读字符 
用 法: int getchar(void); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void) 
{ 
int c; </PRE>
<PRE>/* Note that getchar reads from stdin and 
is line buffered; this means it will 
not return until you press ENTER. */ </PRE>
<PRE>while ((c = getchar()) != '\n') 
printf(&quot;%c&quot;, c); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getche </font>
功 能: 从控制台取字符(带回显) 
用 法: int getche(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char ch; </PRE>
<PRE>printf(&quot;Input a character:&quot;); 
ch = getche(); 
printf(&quot;\nYou input a '%c'\n&quot;, ch); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getcolor </font>
功 能: 返回当前画线颜色 
用 法: int far getcolor(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int color, midx, midy; 
char colname[35]; </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; 
setcolor(getmaxcolor()); </PRE>
<PRE>/* for centering text on the display */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* get the current drawing color */ 
color = getcolor(); </PRE>
<PRE>/* convert color value into a string */ 
itoa(color, colname, 10); 
strcat(colname, 
&quot; is the current drawing color.&quot;); </PRE>
<PRE>/* display a message */ 
outtextxy(midx, midy, colname); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getcurdir </font>
功 能: 取指定驱动器的当前目录 
用 法: int getcurdir(int drive, char *direc); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>char *current_directory(char *path) 
{ 
strcpy(path, &quot;X:\\&quot;); /* 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); 
} </PRE>
<PRE>int main(void) 
{ 
char curdir[MAXPATH]; </PRE>
<PRE>current_directory(curdir); 
printf(&quot;The current directory is %s\n&quot;, curdir); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getcwd </font>
功 能: 取当前工作目录 
用 法: char *getcwd(char *buf, int n); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char buffer[MAXPATH]; </PRE>
<PRE>getcwd(buffer, MAXPATH); 
printf(&quot;The current directory is: %s\n&quot;, buffer); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getdate </font>
功 能: 取DOS日期 
用 法: void getdate(struct *dateblk); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
struct date d; </PRE>
<PRE>getdate(&amp;d); 
printf(&quot;The current year is: %d\n&quot;, 
d.da_year); 
printf(&quot;The current day is: %d\n&quot;, 
d.da_day); 
printf(&quot;The current month is: %d\n&quot;, 
d.da_mon); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getdefaultpalette </font>
功 能: 返回调色板定义结构 
用 法: struct palettetype *far getdefaultpalette(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int i; </PRE>
<PRE>/* structure for returning palette copy */ 
struct palettetype far *pal=(void *) 0; </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>setcolor(getmaxcolor()); </PRE>
<PRE>/* return a pointer to the default palette */ 
pal = getdefaultpalette(); </PRE>
<PRE>for (i=0; i&lt;16; i++) 
{ 
printf(&quot;colors[%d] = %d\n&quot;, i, 
pal-&gt;colors[i]); 
getch(); 
} </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> getdisk </font>
功 能: 取当前磁盘驱动器号 
用 法: int getdisk(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
int disk; </PRE>
<PRE>disk = getdisk() + 'A'; 
printf(&quot;The current drive is: %c\n&quot;, 
disk); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getdrivername </font>
功 能: 返回指向包含当前图形驱动程序名字的字符串指针 
用 法: char *getdrivename(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; </PRE>
<PRE>/* stores the device driver name */ 
char *drivername; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 

⌨️ 快捷键说明

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