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

📄 s.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<PRE>#include 
#include 
#include </PRE>
<PRE>#define INTR 0X1C /* The clock tick interrupt */ </PRE>
<PRE>void interrupt ( *oldhandler)(void); </PRE>
<PRE>int count=0; </PRE>
<PRE>void interrupt handler(void) 
{ 
/* increase the global counter */ 
count++; </PRE>
<PRE>/* call the old routine */ 
oldhandler(); 
} </PRE>
<PRE>int main(void) 
{ 
/* save the old interrupt vector */ 
oldhandler = getvect(INTR); </PRE>
<PRE>/* install the new interrupt handler */ 
setvect(INTR, handler); </PRE>
<PRE>/* loop until the counter exceeds 20 */ 
while (count &lt; 20) 
printf(&quot;count is %d\n&quot;,count); </PRE>
<PRE>/* reset the old interrupt handler */ 
setvect(INTR, oldhandler); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setverify </font>
功 能: 设置验证状态 
用 法: void setverify(int value); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int verify_flag; </PRE>
<PRE>printf(&quot;Enter 0 to set verify flag off\n&quot;); 
printf(&quot;Enter 1 to set verify flag on\n&quot;); </PRE>
<PRE>verify_flag = getch() - 0; </PRE>
<PRE>setverify(verify_flag); </PRE>
<PRE>if (getverify()) 
printf(&quot;DOS verify flag is on\n&quot;); 
else 
printf(&quot;DOS verify flag is off\n&quot;); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">setviewport </font>
功 能: 为图形输出设置当前视口 
用 法: void far setviewport(int left, int top, int right, 
int bottom, int clipflag); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>#define CLIP_ON 1 /* activates clipping in viewport */ </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(); 
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>setcolor(getmaxcolor()); </PRE>
<PRE>/* message in default full-screen viewport */ 
outtextxy(0, 0, &quot;* &lt;-- (0, 0) in default viewport&quot;); </PRE>
<PRE>/* create a smaller viewport */ 
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </PRE>
<PRE>/* display some text */ 
outtextxy(0, 0, &quot;* &lt;-- (0, 0) in smaller viewport&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> setvisualpage </font>
功 能: 设置可见图形页号 
用 法: void far setvisualpage(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">setwritemode </font>
功 能: 设置图形方式下画线的输出模式 
用 法: void far setwritemode(int mode); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main() 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int xmax, ymax; </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>xmax = getmaxx(); 
ymax = getmaxy(); </PRE>
<PRE>/* select XOR drawing mode */ 
setwritemode(XOR_PUT); </PRE>
<PRE>/* draw a line */ 
line(0, 0, xmax, ymax); 
getch(); </PRE>
<PRE>/* erase the line by drawing over it */ 
line(0, 0, xmax, ymax); 
getch(); </PRE>
<PRE>/* select overwrite drawing mode */ 
setwritemode(COPY_PUT); </PRE>
<PRE>/* draw a line */ 
line(0, 0, xmax, ymax); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> signal </font>
功 能: 设置某一信号的对应动作 
用 法: int signal(int sig, sigfun fname); 
程序例: </PRE>
<PRE>/* This example installs a signal handler routine for SIGFPE, 
catches an integer overflow condition, makes an adjustment 
to AX register, and returns. This example program MAY cause 
your computer to crash, and will produce runtime errors 
depending on which memory model is used. 
*/ </PRE>
<PRE>#pragma inline 
#include 
#include </PRE>
<PRE>void Catcher(int sig, int type, int *reglist) 
{ 
printf(&quot;Caught it!\n&quot;); 
*(reglist + 8) = 3; /* make return AX = 3 */ 
} </PRE>
<PRE>int main(void) 
{ 
signal(SIGFPE, Catcher); 
asm mov ax,07FFFH /* AX = 32767 */ 
asm inc ax /* cause overflow */ 
asm into /* activate handler */ </PRE>
<PRE>/* The handler set AX to 3 on return. If that hadn't happened, 
there would have been another exception when the next 'into' 
was executed after the 'dec' instruction. */ 
asm dec ax /* no overflow now */ 
asm into /* doesn't activate */ 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sin </font>
功 能: 正弦函数 
用 法: double sin(double x); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
double result, x = 0.5; </PRE>
<PRE>result = sin(x); 
printf(&quot;The sin() of %lf is %lf\n&quot;, x, result); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sinh </font>
功 能: 双曲正弦函数 
用 法: double sinh(double x); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
double result, x = 0.5; </PRE>
<PRE>result = sinh(x); 
printf(&quot;The hyperbolic sin() of %lf is %lf\n&quot;, x, result); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sleep </font>
功 能: 执行挂起一段时间 
用 法: unsigned sleep(unsigned seconds); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
int i; </PRE>
<PRE>for (i=1; i&lt;5; i++) 
{ 
printf(&quot;Sleeping for %d seconds\n&quot;, i); 
sleep(i); 
} 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sopen</font>
功 能: 打开一共享文件 
用 法: int sopen(char *pathname, int access, int shflag, int permiss); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int handle; 
int status; </PRE>
<PRE>handle = sopen(&quot;c:\\autoexec.bat&quot;, O_RDONLY, SH_DENYNO, S_IREAD); </PRE>
<PRE>if (!handle) 
{ 
printf(&quot;sopen failed\n&quot;); 
exit(1); 
} </PRE>
<PRE>status = access(&quot;c:\\autoexec.bat&quot;, 6); 
if (status == 0) 
printf(&quot;read/write access allowed\n&quot;); 
else 
printf(&quot;read/write access not allowed\n&quot;); </PRE>
<PRE>close(handle); 
return 0; 
} 


</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> sound </font>
功 能: 以指定频率打开PC扬声器 
用 法: void sound(unsigned frequency); 
程序例: </PRE>
<PRE>/* Emits a 7-Hz tone for 10 seconds. 
Your PC may not be able to emit a 7-Hz tone. */ 
#include </PRE>
<PRE>int main(void) 
{ 
sound(7); 
delay(10000); 
nosound(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">spawnl </font>
功 能: 创建并运行子程序 
用 法: int spawnl(int mode, char *pathname, char *arg0, 
arg1, ... argn, NULL); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int result; </PRE>
<PRE>clrscr(); 
result = spawnl(P_WAIT, &quot;tcc.exe&quot;, NULL); 
if (result == -1) 
{ 
perror(&quot;Error from spawnl&quot;); 
exit(1); 
} 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> spawnle </font>
功 能: 创建并运行子程序 
用 法: int spawnle(int mode, char *pathname, char *arg0, 
arg1,..., argn, NULL); 
程序例: </PRE>
<PRE>/* spawnle() example */ </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int result; </PRE>
<PRE>clrscr(); 
result = spawnle(P_WAIT, &quot;tcc.exe&quot;, NULL, NULL); 
if (result == -1) 
{ 
perror(&quot;Error from spawnle&quot;); 
exit(1); 
} 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sprintf </font>
功 能: 送格式化输出到字符串中 
用 法: int sprintf(char *string, char *farmat [,argument,...]); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char buffer[80]; </PRE>
<PRE>sprintf(buffer, &quot;An approximation of Pi is %f\n&quot;, M_PI); 
puts(buffer); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sqrt </font>
功 能: 计算平方根 
用 法: double sqrt(double x); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
double x = 4.0, result; </PRE>
<PRE>result = sqrt(x); 
printf(&quot;The square root of %lf is %lf\n&quot;, x, result); 
return 0; 
} 
</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> srand </font>
功 能: 初始化随机数发生器 
用 法: void srand(unsigned seed); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int i; 
time_t t; </PRE>
<PRE>srand((unsigned) time(&amp;t)); 
printf(&quot;Ten random numbers from 0 to 99\n\n&quot;); 
for(i=0; i&lt;10; i++) 
printf(&quot;%d\n&quot;, rand() % 100); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">sscanf </font>
功 能: 执行从字符串中的格式化输入 
用 法: int sscanf(char *string, 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>

⌨️ 快捷键说明

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