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

📄 s.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<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>函数大全(s开头)
</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sbrk </font>
功 能: 改变数据段空间位置 
用 法: char *sbrk(int incr); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
printf(&quot;Changing allocation with sbrk()\n&quot;); 
printf(&quot;Before sbrk() call: %lu bytes free\n&quot;, 
(unsigned long) coreleft()); 
sbrk(1000); 
printf(&quot; After sbrk() call: %lu bytes free\n&quot;, 
(unsigned long) coreleft()); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">scanf </font>
功 能: 执行格式化输入 
用 法: int scanf(char *format[,argument,...]); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char label[20]; 
char name[20]; 
int entries = 0; 
int loop, age; 
double salary; </PRE>
<PRE>struct Entry_struct 
{ 
char name[20]; 
int age; 
float salary; 
} entry[20]; </PRE>
<PRE>/* Input a label as a string of characters restricting to 20 characters */ 
printf(&quot;\n\nPlease enter a label for the chart: &quot;); 
scanf(&quot;%20s&quot;, label); 
fflush(stdin); /* flush the input stream in case of bad input */ </PRE>
<PRE>/* Input number of entries as an integer */ 
printf(&quot;How many entries will there be? (less than 20) &quot;); 
scanf(&quot;%d&quot;, &amp;entries); 
fflush(stdin); /* flush the input stream in case of bad input */ </PRE>
<PRE>/* input a name restricting input to only letters upper or lower case */ 
for (loop=0;loop { 
printf(&quot;Entry %d\n&quot;, loop); 
printf(&quot; Name : &quot;); 
scanf(&quot;%[A-Za-z]&quot;, entry[loop].name); 
fflush(stdin); /* flush the input stream in case of bad input */ </PRE>
<PRE>/* input an age as an integer */ 
printf(&quot; Age : &quot;); 
scanf(&quot;%d&quot;, &amp;entry[loop].age); 
fflush(stdin); /* flush the input stream in case of bad input */ </PRE>
<PRE>/* input a salary as a float */ 
printf(&quot; Salary : &quot;); 
scanf(&quot;%f&quot;, &amp;entry[loop].salary); 
fflush(stdin); /* flush the input stream in case of bad input */ 
} </PRE>
<PRE>/* Input a name, age and salary as a string, integer, and double */ 
printf(&quot;\nPlease enter your name, age and salary\n&quot;); 
scanf(&quot;%20s %d %lf&quot;, name, &amp;age, &amp;salary); 
</PRE>
<PRE>/* Print out the data that was input */ 
printf(&quot;\n\nTable %s\n&quot;,label); 
printf(&quot;Compiled by %s age %d $%15.2lf\n&quot;, name, age, salary); 
printf(&quot;-----------------------------------------------------\n&quot;); 
for (loop=0;loop printf(&quot;%4d | %-20s | %5d | %15.2lf\n&quot;, 
loop + 1, 
entry[loop].name, 
entry[loop].age, 
entry[loop].salary); 
printf(&quot;-----------------------------------------------------\n&quot;); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> searchpath </font>
功 能: 搜索DOS路径 
用 法: char *searchpath(char *filename); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *p; </PRE>
<PRE>/* Looks for TLINK and returns a pointer 
to the path */ 
p = searchpath(&quot;TLINK.EXE&quot;); 
printf(&quot;Search for TLINK.EXE : %s\n&quot;, p); </PRE>
<PRE>/* Looks for non-existent file */ 
p = searchpath(&quot;NOTEXIST.FIL&quot;); 
printf(&quot;Search for NOTEXIST.FIL : %s\n&quot;, p); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sector </font>
功 能: 画并填充椭圆扇区 
用 法: void far sector(int x, int y, int stangle, int endangle); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy, i; 
int stangle = 45, endangle = 135; 
int xrad = 100, yrad = 50; </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 the fill patterns */ 
for (i=EMPTY_FILL; i { 
/* set the fill style */ 
setfillstyle(i, getmaxcolor()); </PRE>
<PRE>/* draw the sector slice */ 
sector(midx, midy, stangle, endangle, xrad, yrad); </PRE>
<PRE>getch(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} 
</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> segread </font>
功 能: 读段寄存器值 
用 法: void segread(struct SREGS *segtbl); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
struct SREGS segs; </PRE>
<PRE>segread(&amp;segs); 
printf(&quot;Current segment register settings\n\n&quot;); 
printf(&quot;CS: %X DS: %X\n&quot;, segs.cs, segs.ds); 
printf(&quot;ES: %X SS: %X\n&quot;, segs.es, segs.ss); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setactivepage </font>
功 能: 设置图形输出活动页 
用 法: void far setactivepage(int pagenum); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* select a driver and mode that supports */ 
/* multiple pages. */ 
int gdriver = EGA, gmode = EGAHI, errorcode; 
int x, y, ht; </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>x = getmaxx() / 2; 
y = getmaxy() / 2; 
ht = textheight(&quot;W&quot;); </PRE>
<PRE>/* select the off screen page for drawing */ 
setactivepage(1); </PRE>
<PRE>/* draw a line on page #1 */ 
line(0, 0, getmaxx(), getmaxy()); </PRE>
<PRE>/* output a message on page #1 */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(x, y, &quot;This is page #1:&quot;); 
outtextxy(x, y+ht, &quot;Press any key to halt:&quot;); </PRE>
<PRE>/* select drawing to page #0 */ 
setactivepage(0); </PRE>
<PRE>/* output a message on page #0 */ 
outtextxy(x, y, &quot;This is page #0.&quot;); 
outtextxy(x, y+ht, &quot;Press any key to view page #1:&quot;); 
getch(); </PRE>
<PRE>/* select page #1 as the visible page */ 
setvisualpage(1); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setallpallette </font>
功 能: 按指定方式改变所有的调色板颜色 
用 法: void far setallpallette(struct palette, far *pallette); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
struct palettetype pal; 
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>/* grab a copy of the palette */ 
getpalette(&amp;pal); </PRE>
<PRE>/* display the default palette 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>/* restore the palette colors */ 
setallpalette(&amp;pal); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setaspectratio </font>
功 能: 设置图形纵横比 
用 法: void far setaspectratio(int xasp, int 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(); 
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; 
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>/* claer the screen */ 
cleardevice(); </PRE>
<PRE>/* adjust the aspect for a wide circle */ 
setaspectratio(xasp/2, yasp); 
circle(midx, midy, 100); 
getch(); </PRE>
<PRE>/* adjust the aspect for a 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">setbkcolor </font>
功 能: 用调色板设置当前背景颜色 
用 法: void far setbkcolor(int color); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* select a driver and mode that supports */ 
/* multiple background colors. */ 
int gdriver = EGA, gmode = EGAHI, errorcode; 
int bkcol, maxcolor, x, y; 
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>/* maximum color index supported */ 
maxcolor = getmaxcolor(); </PRE>
<PRE>/* for centering text messages */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
x = getmaxx() / 2; 
y = getmaxy() / 2; </PRE>
<PRE>/* loop through the available colors */ 
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++) 
{ 
/* clear the screen */ 
cleardevice(); </PRE>
<PRE>/* select a new background color */ 
setbkcolor(bkcol); </PRE>
<PRE>/* output a messsage */ 
if (bkcol == WHITE) 
setcolor(EGA_BLUE); 
sprintf(msg, &quot;Background color: %d&quot;, bkcol); 
outtextxy(x, y, msg); 
getch(); 
} </PRE>
<PRE>/* clean up */ 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setblock </font>
功 能: 修改先前已分配的DOS存储段大小 
用 法: int setblock(int seg, int newsize); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
unsigned int size, segp; 
int stat; </PRE>
<PRE>size = 64; /* (64 x 16) = 1024 bytes */ 
stat = allocmem(size, &amp;segp); 
if (stat == -1) 
printf(&quot;Allocated memory at segment: %X\n&quot;, segp); 
else 
{ 
printf(&quot;Failed: maximum number of paragraphs available is %d\n&quot;, 
stat); 
exit(1); 
} </PRE>
<PRE>stat = setblock(segp, size * 2); 
if (stat == -1) 
printf(&quot;Expanded memory block at segment: %X\n&quot;, segp); 
else 
printf(&quot;Failed: maximum number of paragraphs available is %d\n&quot;, 
stat); </PRE>
<PRE>freemem(segp); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setbuf </font>
功 能: 把缓冲区与流相联 
用 法: void setbuf(FILE *steam, char *buf); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>/* BUFSIZ is defined in stdio.h */ 
char outbuf[BUFSIZ]; </PRE>
<PRE>int main(void) 
{ 
/* attach a buffer to the standard output stream */ 
setbuf(stdout, outbuf); </PRE>
<PRE>/* put some characters into the buffer */ 
puts(&quot;This is a test of buffered output.\n\n&quot;); 
puts(&quot;This output will go into outbuf\n&quot;); 
puts(&quot;and won't appear until the buffer\n&quot;); 
puts(&quot;fills up or we flush the stream.\n&quot;); </PRE>
<PRE>/* flush the output buffer */ 
fflush(stdout); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setcbrk </font>
功 能: 设置Control-break 
用 法: int setcbrk(int value); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int break_flag; </PRE>
<PRE>printf(&quot;Enter 0 to turn control break off\n&quot;); 
printf(&quot;Enter 1 to turn control break on\n&quot;); </PRE>
<PRE>break_flag = getch() - 0; </PRE>
<PRE>setcbrk(break_flag); </PRE>
<PRE>if (getcbrk()) 
printf(&quot;Cntrl-brk flag is on\n&quot;); 
else 

⌨️ 快捷键说明

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