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

📄 g.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<PRE>void interrupt get_out(); /* interrupt prototype */ </PRE>
<PRE>void interrupt (*oldfunc)(); /* interrupt function pointer */ 
int looping = 1; </PRE>
<PRE>int main(void) 
{ 
puts(&quot;Press to terminate&quot;); </PRE>
<PRE>/* save the old interrupt */ 
oldfunc = getvect(5); </PRE>
<PRE>/* install interrupt handler */ 
setvect(5,get_out); </PRE>
<PRE>/* do nothing */ 
while (looping); </PRE>
<PRE>/* restore to original interrupt routine */ 
setvect(5,oldfunc); </PRE>
<PRE>puts(&quot;Success&quot;); 
return 0; 
} 
void interrupt get_out() 
{ 
looping = 0; /* change global variable to get out of loop */ 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getverify </font>
功 能: 返回DOS校验标志状态 
用 法: int getverify(void); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
if (getverify()) 
printf(&quot;DOS verify flag is on\n&quot;); 
else 
printf(&quot;DOS verify flag is off\n&quot;); 
return 0; 
} 
</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getviewsetting </font>
功 能: 返回有关当前视区的信息 
用 法: void far getviewsettings(struct viewporttype far *viewport); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>char *clip[] = { &quot;OFF&quot;, &quot;ON&quot; }; </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
struct viewporttype viewinfo; 
int midx, midy, ht; 
char topstr[80], botstr[80], clipstr[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 viewport */ 
getviewsettings(&amp;viewinfo); </PRE>
<PRE>/* convert text information into strings */ 
sprintf(topstr, &quot;(%d, %d) is the upper left viewport corner.&quot;, 
viewinfo.left, viewinfo.top); 
sprintf(botstr, &quot;(%d, %d) is the lower right viewport corner.&quot;, 
viewinfo.right, viewinfo.bottom); 
sprintf(clipstr, &quot;Clipping is turned %s.&quot;, clip[viewinfo.clip]); </PRE>
<PRE>/* display the information */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
ht = textheight(&quot;W&quot;); 
outtextxy(midx, midy, topstr); 
outtextxy(midx, midy+2*ht, botstr); 
outtextxy(midx, midy+4*ht, clipstr); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getw </font>
功 能: 从流中取一整数 
用 法: int getw(FILE *strem); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>#define FNAME &quot;test.$$$&quot; </PRE>
<PRE>int main(void) 
{ 
FILE *fp; 
int word; </PRE>
<PRE>/* place the word in a file */ 
fp = fopen(FNAME, &quot;wb&quot;); 
if (fp == NULL) 
{ 
printf(&quot;Error opening file %s\n&quot;, FNAME); 
exit(1); 
} </PRE>
<PRE>word = 94; 
putw(word,fp); 
if (ferror(fp)) 
printf(&quot;Error writing to file\n&quot;); 
else 
printf(&quot;Successful write\n&quot;); 
fclose(fp); </PRE>
<PRE>/* reopen the file */ 
fp = fopen(FNAME, &quot;rb&quot;); 
if (fp == NULL) 
{ 
printf(&quot;Error opening file %s\n&quot;, FNAME); 
exit(1); 
} </PRE>
<PRE>/* extract the word */ 
word = getw(fp); 
if (ferror(fp)) 
printf(&quot;Error reading file\n&quot;); 
else 
printf(&quot;Successful read: word = %d\n&quot;, word); </PRE>
<PRE>/* clean up */ 
fclose(fp); 
unlink(FNAME); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">getx </font>
功 能: 返回当前图形位置的x坐标 
用 法: int far getx(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
char msg[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>/* move to the screen center point */ 
moveto(getmaxx() / 2, getmaxy() / 2); </PRE>
<PRE>/* create a message string */ 
sprintf(msg, &quot;&lt;-(%d, %d) is the here.&quot;, getx(), gety()); </PRE>
<PRE>/* display the message */ 
outtext(msg); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">gety </font>
功 能: 返回当前图形位置的y坐标 
用 法: int far gety(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
char msg[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>/* move to the screen center point */ 
moveto(getmaxx() / 2, getmaxy() / 2); </PRE>
<PRE>/* create a message string */ 
sprintf(msg, &quot;&lt;-(%d, %d) is the here.&quot;, getx(), gety()); </PRE>
<PRE>/* display the message */ 
outtext(msg); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">gmtime </font>
功 能: 把日期和时间转换为格林尼治标准时间(GMT) 
用 法: struct tm *gmtime(long *clock); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>/* Pacific Standard Time &amp; Daylight Savings */ 
char *tzstr = &quot;TZ=PST8PDT&quot;; </PRE>
<PRE>int main(void) 
{ 
time_t t; 
struct tm *gmt, *area; </PRE>
<PRE>putenv(tzstr); 
tzset(); </PRE>
<PRE>t = time(NULL); 
area = localtime(&amp;t); 
printf(&quot;Local time is: %s&quot;, asctime(area)); 
gmt = gmtime(&amp;t); 
printf(&quot;GMT is: %s&quot;, asctime(gmt)); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> gotoxy </font>
功 能: 在文本窗口中设置光标 
用 法: void gotoxy(int x, int y); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void) 
{ 
clrscr(); 
gotoxy(35, 12); 
cprintf(&quot;Hello world&quot;); 
getch(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">gotoxy </font>
功 能: 在文本窗口中设置光标 
用 法: void gotoxy(int x, int y); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void) 
{ 
clrscr(); 
gotoxy(35, 12); 
cprintf(&quot;Hello world&quot;); 
getch(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">graphdefaults</font> 
功 能: 将所有图形设置复位为它们的缺省值 
用 法: void far graphdefaults(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int maxx, maxy; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;c:\\bor\\Borland\\bgi&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(); </PRE>
<PRE>/* output line with non-default settings */ 
setlinestyle(DOTTED_LINE, 0, 3); 
line(0, 0, maxx, maxy); 
outtextxy(maxx/2, maxy/3, &quot;Before default values are restored.&quot;); 
getch(); </PRE>
<PRE>/* restore default values for everything */ 
graphdefaults(); </PRE>
<PRE>/* clear the screen */ 
cleardevice(); </PRE>
<PRE>/* output line with default settings */ 
line(0, 0, maxx, maxy); 
outtextxy(maxx/2, maxy/3, &quot;After restoring default values.&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">grapherrormsg </font>
功 能: 返回一个错误信息串的指针 
用 法: char *far grapherrormsg(int errorcode); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>#define NONSENSE -50 </PRE>
<PRE>int main(void) 
{ 
/* FORCE AN ERROR TO OCCUR */ 
int gdriver = NONSENSE, gmode, errorcode; </PRE>
<PRE>/* initialize graphics mode */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); </PRE>
<PRE>/* if an error occurred, then output a */ 
/* descriptive error message. */ 
if (errorcode != grOk) 
{ 
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>/* draw a line */ 
line(0, 0, getmaxx(), getmaxy()); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">graphresult </font>
功 能: 返回最后一次不成功的图形操作的错误代码 
用 法: int far graphresult(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); </PRE>
<PRE>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>/* draw a line */ 
line(0, 0, getmaxx(), getmaxy()); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 
</PRE>
<PRE>函数名: <font size="5" color="#FF0000">_graphfreemem </font>
功 能: 用户可修改的图形存储区释放函数 
用 法: void far _graphfreemem(void far *ptr, unsigned size); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy; </PRE>
<PRE>/* clear the text screen */ 
clrscr(); 
printf(&quot;Press any key to initialize graphics mode:&quot;); 
getch(); 
clrscr(); </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>/* display a message */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(midx, midy, &quot;Press any key to exit graphics mode:&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} </PRE>
<PRE>/* called by the graphics kernel to allocate memory */ 
void far * far _graphgetmem(unsigned size) 
{ 
printf(&quot;_graphgetmem called to allocate %d bytes.\n&quot;, size); 
printf(&quot;hit any key:&quot;); 
getch(); 
printf(&quot;\n&quot;); </PRE>
<PRE>/* allocate memory from far heap */ 
return farmalloc(size); 
} </PRE>
<PRE>/* called by the graphics kernel to free memory */ 
void far _graphfreemem(void far *ptr, unsigned size) 
{ 
printf(&quot;_graphfreemem called to free %d bytes.\n&quot;, size); 
printf(&quot;hit any key:&quot;); 
getch(); 
printf(&quot;\n&quot;); </PRE>
<PRE>/* free ptr from far heap */ 
farfree(ptr); 
} 
</PRE>
<PRE>函数名: _<font size="5" color="#FF0000">graphgetmem </font>
功 能: 用户可修改的图形存储区分配函数 
用 法: void far *far _graphgetmem(unsigned size); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request autodetection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy; </PRE>
<PRE>/* clear the text screen */ 
clrscr(); 
printf(&quot;Press any key to initialize graphics mode:&quot;); 
getch(); 
clrscr(); </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>/* display a message */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(midx, midy, &quot;Press any key to exit graphics mode:&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} </PRE>
<PRE>/* called by the graphics kernel to allocate memory */ 
void far * far _graphgetmem(unsigned size) 
{ 
printf(&quot;_graphgetmem called to allocate %d bytes.\n&quot;, size); 
printf(&quot;hit any key:&quot;); 
getch(); 
printf(&quot;\n&quot;); </PRE>
<PRE>/* allocate memory from far heap */ 
return farmalloc(size); 
} </PRE>
<PRE>/* called by the graphics kernel to free memory */ 
void far _graphfreemem(void far *ptr, unsigned size) 
{ 
printf(&quot;_graphfreemem called to free %d bytes.\n&quot;, size); 
printf(&quot;hit any key:&quot;); 
getch(); 
printf(&quot;\n&quot;); </PRE>
<PRE>/* free ptr from far heap */ 
farfree(ptr); 
}</PRE>
<p> </p>

<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>资料收集:beck Copyright 2004 张求熙, All Rights Reserved</pre>
<pre><a href="mailto:Email:qiuxi1984@126.com">Email:qiuxi1984@126.com</a>     QQ:35540948 </pre>

⌨️ 快捷键说明

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