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

📄 s.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<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>/* a user defined line pattern */ 
/* binary: &quot;0000000000000001&quot; */ 
userpat = 1; </PRE>
<PRE>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++) 
{ 
/* select the line style */ 
setlinestyle(style, userpat, 1); </PRE>
<PRE>/* convert style into a string */ 
strcpy(stylestr, lname[style]); </PRE>
<PRE>/* draw a line */ 
line(0, 0, midx-10, midy); </PRE>
<PRE>/* draw a rectangle */ 
rectangle(0, 0, getmaxx(), getmaxy()); </PRE>
<PRE>/* output a message */ 
outtextxy(midx, midy, stylestr); </PRE>
<PRE>/* wait for a key */ 
getch(); 
cleardevice(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setmem </font>
功 能: 存值到存储区 
用 法: void setmem(void *addr, int len, char value); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *dest; </PRE>
<PRE>dest = calloc(21, sizeof(char)); 
setmem(dest, 20, 'c'); 
printf(&quot;%s\n&quot;, dest); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> setmode </font>
功 能: 设置打开文件方式 
用 法: int setmode(int handle, unsigned mode); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int result; </PRE>
<PRE>result = setmode(fileno(stdprn), O_TEXT); 
if (result == -1) 
perror(&quot;Mode not available\n&quot;); 
else 
printf(&quot;Mode successfully switched\n&quot;); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setpalette </font>
功 能: 改变调色板的颜色 
用 法: void far setpalette(int index, int actural_color); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int color, maxcolor, ht; 
int y = 10; 
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>maxcolor = getmaxcolor(); 
ht = 2 * textheight(&quot;W&quot;); </PRE>
<PRE>/* display the default colors */ 
for (color=1; color&lt;=maxcolor; color++) 
{ 
setcolor(color); 
sprintf(msg, &quot;Color: %d&quot;, color); 
outtextxy(1, y, msg); 
y += ht; 
} </PRE>
<PRE>/* wait for a key */ 
getch(); </PRE>
<PRE>/* black out the colors one by one */ 
for (color=1; color&lt;=maxcolor; color++) 
{ 
setpalette(color, BLACK); 
getch(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setrgbpalette </font>
功 能: 定义IBM8514图形卡的颜色 
用 法: void far setrgbpalette(int colornum, int red, int green, int blue); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* select a driver and mode that supports the use */ 
/* of the setrgbpalette function. */ 
int gdriver = VGA, gmode = VGAHI, errorcode; 
struct palettetype pal; 
int i, ht, y, xmax; </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>/* grab a copy of the palette */ 
getpalette(&amp;pal); </PRE>
<PRE>/* create gray scale */ 
for (i=0; i setrgbpalette(pal.colors[i], i*4, i*4, i*4); </PRE>
<PRE>/* display the gray scale */ 
ht = getmaxy() / 16; 
xmax = getmaxx(); 
y = 0; 
for (i=0; i { 
setfillstyle(SOLID_FILL, i); 
bar(0, y, xmax, y+ht); 
y += ht; 
} </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">settextjustify </font>
功 能: 为图形函数设置文本的对齐方式 
用 法: void far settextjustify(int horiz, int vert); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>/* function prototype */ 
void xat(int x, int y); </PRE>
<PRE>/* horizontal text justification settings */ 
char *hjust[] = { &quot;LEFT_TEXT&quot;, 
&quot;CENTER_TEXT&quot;, 
&quot;RIGHT_TEXT&quot; 
}; </PRE>
<PRE>/* vertical text justification settings */ 
char *vjust[] = { &quot;LEFT_TEXT&quot;, 
&quot;CENTER_TEXT&quot;, 
&quot;RIGHT_TEXT&quot; 
}; </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy, hj, vj; 
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>midx = getmaxx() / 2; 
midy = getmaxy() / 2; </PRE>
<PRE>/* loop through text justifications */ 
for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) 
for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++) 
{ 
cleardevice(); 
/* set the text justification */ 
settextjustify(hj, vj); </PRE>
<PRE>/* create a message string */ 
sprintf(msg, &quot;%s %s&quot;, hjust[hj], vjust[vj]); </PRE>
<PRE>/* create cross hairs on the screen */ 
xat(midx, midy); </PRE>
<PRE>/* output the message */ 
outtextxy(midx, midy, msg); 
getch(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} </PRE>
<PRE>/* draw an &quot;x&quot; at (x, y) */ 
void xat(int x, int y) 
{ 
line(x-4, y, x+4, y); 
line(x, y-4, x, y+4); 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">settextstyle </font>
功 能: 为图形输出设置当前的文本属性 
用 法: void far settextstyle (int font, int direction, char size); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>/* the names of the text styles supported */ 
char *fname[] = { &quot;DEFAULT font&quot;, 
&quot;TRIPLEX font&quot;, 
&quot;SMALL font&quot;, 
&quot;SANS SERIF font&quot;, 
&quot;GOTHIC font&quot; 
}; </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int style, midx, midy; 
int size = 1; </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>settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* loop through the available text styles */ 
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 
{ 
cleardevice(); 
if (style == TRIPLEX_FONT) 
size = 4; </PRE>
<PRE>/* select the text style */ 
settextstyle(style, HORIZ_DIR, size); </PRE>
<PRE>/* output a message */ 
outtextxy(midx, midy, fname[style]); 
getch(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">settextstyle </font>
功 能: 为图形输出设置当前的文本属性 
用 法: void far settextstyle (int font, int direction, char size); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>/* the names of the text styles supported */ 
char *fname[] = { &quot;DEFAULT font&quot;, 
&quot;TRIPLEX font&quot;, 
&quot;SMALL font&quot;, 
&quot;SANS SERIF font&quot;, 
&quot;GOTHIC font&quot; 
}; </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int style, midx, midy; 
int size = 1; </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>settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* loop through the available text styles */ 
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 
{ 
cleardevice(); 
if (style == TRIPLEX_FONT) 
size = 4; </PRE>
<PRE>/* select the text style */ 
settextstyle(style, HORIZ_DIR, size); </PRE>
<PRE>/* output a message */ 
outtextxy(midx, midy, fname[style]); 
getch(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">settime </font>
功 能: 设置系统时间 
用 法: void settime(struct time *timep); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
struct time t; </PRE>
<PRE>gettime(&amp;t); 
printf(&quot;The current minute is: %d\n&quot;, t.ti_min); 
printf(&quot;The current hour is: %d\n&quot;, t.ti_hour); 
printf(&quot;The current hundredth of a second is: %d\n&quot;, t.ti_hund); 
printf(&quot;The current second is: %d\n&quot;, t.ti_sec); </PRE>
<PRE>/* Add one to the minutes struct element and then call settime */ 
t.ti_min++; 
settime(&amp;t); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setusercharsize </font>
功 能: 为矢量字体改变字符宽度和高度 
用 法: void far setusercharsize(int multx, int dirx, int multy, int diry); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request autodetection */ 
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(); 
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>/* select a text style */ 
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </PRE>
<PRE>/* move to the text starting position */ 
moveto(0, getmaxy() / 2); </PRE>
<PRE>/* output some normal text */ 
outtext(&quot;Norm &quot;); </PRE>
<PRE>/* make the text 1/3 the normal width */ 
setusercharsize(1, 3, 1, 1); 
outtext(&quot;Short &quot;); </PRE>
<PRE>/* make the text 3 times normal width */ 
setusercharsize(3, 1, 1, 1); 
outtext(&quot;Wide&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 
</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setvbuf </font>
功 能: 把缓冲区与流相关 
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void) 
{ 
FILE *input, *output; 
char bufr[512]; </PRE>
<PRE>input = fopen(&quot;file.in&quot;, &quot;r+b&quot;); 
output = fopen(&quot;file.out&quot;, &quot;w&quot;); </PRE>
<PRE>/* set up input stream for minimal disk access, 
using our own character buffer */ 
if (setvbuf(input, bufr, _IOFBF, 512) != 0) 
printf(&quot;failed to set up buffer for input file\n&quot;); 
else 
printf(&quot;buffer set up for input file\n&quot;); </PRE>
<PRE>/* set up output stream for line buffering using space that 
will be obtained through an indirect call to malloc */ 
if (setvbuf(output, NULL, _IOLBF, 132) != 0) 
printf(&quot;failed to set up buffer for output file\n&quot;); 
else 
printf(&quot;buffer set up for output file\n&quot;); </PRE>
<PRE>/* perform file I/O here */ </PRE>
<PRE>/* close files */ 
fclose(input); 
fclose(output); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setvect </font>
功 能: 设置中断矢量入口 
用 法: void setvect(int intr_num, void interrupt(*isr)()); 
程序例: </PRE>
<PRE>/***NOTE: 
This is an interrupt service routine. You can NOT compile this 
program with Test Stack Overflow turned on and get an executable 
file which will operate correctly. */ </PRE>

⌨️ 快捷键说明

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