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

📄 王大刚--c语言编程宝典--e.htm

📁 初学者的良师益友。其中包括C的全部教程。
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/024.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->E</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 E" name=keywords>
<META content="王大刚 - C语言编程宝典 - E" name=description>
<STYLE>#page {
	LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
	FONT: 9pt/12pt "宋体"
}
.tt2 {
	FONT: 12pt/15pt "宋体"
}
A {
	TEXT-DECORATION: none
}
A:hover {
	COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>

<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff 
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
  <TBODY>
  <TR>
    <TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A 
      href="http://www.hjflying.8u8.com/cl/025.htm">后一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/023.htm">前一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A 
      href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD>
    <TD class=tt2 width="84%" bgColor=#f5f8f8>
      <CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312 
      color=#ff6666>E</FONT></B></CENTER>
      <HR width="94%" color=#ee9b73 SIZE=1>
      函数名: ecvt <BR>功&nbsp; 能: 把一个浮点数转换为字符串 <BR>用&nbsp; 法: char ecvt(double 
      value, int ndigit, int *decpt, int *sign); <BR>程序例: <BR>
      <P>#include &lt;stdlib.h&gt; <BR>#include &lt;stdio.h&gt; <BR>#include 
      &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; char *string; <BR>&nbsp;&nbsp; 
      double value; <BR>&nbsp;&nbsp; int dec, sign; <BR>&nbsp;&nbsp; int ndig = 
      10; <BR>
      <P>&nbsp;&nbsp; clrscr(); <BR>&nbsp;&nbsp; value = 9.876; <BR>&nbsp;&nbsp; 
      string = ecvt(value, ndig, &amp;dec, &amp;sign); <BR>&nbsp;&nbsp; 
      printf("string = %s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dec = %d \ 
      <BR>&nbsp;&nbsp; sign = %d\n", string, dec, sign); <BR>
      <P>&nbsp;&nbsp; value = -123.45; <BR>&nbsp;&nbsp; ndig= 15; 
      <BR>&nbsp;&nbsp; string = ecvt(value,ndig,&amp;dec,&amp;sign); 
      <BR>&nbsp;&nbsp; printf("string = %s dec = %d sign = %d\n", 
      <BR>&nbsp;&nbsp; string, dec, sign); <BR>&nbsp; <BR>
      <P>&nbsp;&nbsp; value = 0.6789e5; /* scientific <BR>&nbsp;&nbsp; notation 
      */ <BR>&nbsp;&nbsp; ndig = 5; <BR>&nbsp;&nbsp; string = 
      ecvt(value,ndig,&amp;dec,&amp;sign); <BR>&nbsp;&nbsp; printf("string = 
      %s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dec = %d\ 
      <BR>&nbsp;&nbsp; sign = %d\n", string, dec, sign); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: ellipse <BR>功&nbsp; 能: 画一椭圆 <BR>用&nbsp; 法: void far ellipse(int x, 
      int y, int stangle, int endangle, <BR>&nbsp;&nbsp;&nbsp; int xradius, int 
      yradius); <BR>程序例: <BR>
      <P>#include &lt;graphics.h&gt; <BR>#include &lt;stdlib.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;conio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; /* request auto detection */ 
      <BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>&nbsp;&nbsp; 
      int midx, midy; <BR>&nbsp;&nbsp; int stangle = 0, endangle = 360; 
      <BR>&nbsp;&nbsp; int xradius = 100, yradius = 50; <BR>
      <P>&nbsp;&nbsp; /* initialize graphics, local variables */ 
      <BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); <BR>
      <P>&nbsp;&nbsp; /* read result of initialization */ <BR>&nbsp;&nbsp; 
      errorcode = graphresult(); <BR>&nbsp;&nbsp; if (errorcode != grOk) 
      <BR>&nbsp;&nbsp; /* an error occurred */ <BR>&nbsp;&nbsp; { 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; grapherrormsg(errorcode)); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:"); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>&nbsp;&nbsp; /* terminate 
      with an error code */ <BR>&nbsp;&nbsp; } <BR>
      <P>&nbsp;&nbsp; midx = getmaxx() / 2; <BR>&nbsp;&nbsp; midy = getmaxy() / 
      2; <BR>&nbsp;&nbsp; setcolor(getmaxcolor()); <BR>
      <P>&nbsp;&nbsp; /* draw ellipse */ <BR>&nbsp;&nbsp; ellipse(midx, midy, 
      stangle, endangle, <BR>&nbsp;&nbsp;&nbsp; xradius, yradius); <BR>
      <P>&nbsp;&nbsp; /* clean up */ <BR>&nbsp;&nbsp; getch(); <BR>&nbsp;&nbsp; 
      closegraph(); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: enable <BR>功&nbsp; 能: 开放硬件中断 <BR>用&nbsp; 法: void enable(void); 
      <BR>程序例: <BR>
      <P>/* ** NOTE: <BR>This is an interrupt service routine. You can NOT 
      compile this program <BR>with Test Stack Overflow turned on and get an 
      executable file which will <BR>operate correctly. <BR>*/ <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;dos.h&gt; <BR>#include 
      &lt;conio.h&gt; <BR>
      <P>/* The clock tick interrupt */ <BR>#define INTR 0X1C <BR>
      <P>void interrupt ( *oldhandler)(void); <BR>
      <P>int count=0; <BR>
      <P>void interrupt handler(void) <BR>{ <BR>/* <BR>&nbsp;&nbsp; disable 
      interrupts during the handling of the interrupt <BR>*/ <BR>&nbsp;&nbsp; 
      disable(); <BR>/* increase the global counter */ <BR>&nbsp;&nbsp; count++; 
      <BR>/* <BR>&nbsp;&nbsp; re enable interrupts at the end of the handler 
      <BR>*/ <BR>&nbsp;&nbsp; enable(); <BR>/* call the old routine */ 
      <BR>&nbsp;&nbsp; oldhandler(); <BR>} <BR>
      <P>int main(void) <BR>{ <BR>/* save the old interrupt vector */ 
      <BR>&nbsp;&nbsp; oldhandler = getvect(INTR); <BR>
      <P>/* install the new interrupt handler */ <BR>&nbsp;&nbsp; setvect(INTR, 
      handler); <BR>
      <P>/* loop until the counter exceeds 20 */ <BR>&nbsp;&nbsp; while (count 
      &lt; 20) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("count is %d\n",count); 
      <BR>
      <P>/* reset the old interrupt handler */ <BR>&nbsp;&nbsp; setvect(INTR, 
      oldhandler); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: eof <BR>功&nbsp; 能: 检测文件结束 <BR>用&nbsp; 法: int eof(int *handle); 
      <BR>程序例: <BR>
      <P>#include &lt;sys\stat.h&gt; <BR>#include &lt;string.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;fcntl.h&gt; <BR>#include &lt;io.h&gt; 
<BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int handle; <BR>&nbsp;&nbsp; char 
      msg[] = "This is a test"; <BR>&nbsp;&nbsp; char ch; <BR>
      <P>&nbsp;&nbsp; /* create a file */ <BR>&nbsp;&nbsp; handle = 
      open("DUMMY.FIL", <BR>&nbsp;&nbsp; O_CREAT | O_RDWR, <BR>&nbsp;&nbsp; 
      S_IREAD | S_IWRITE); <BR>
      <P>&nbsp;&nbsp; /* write some data to the file */ <BR>&nbsp;&nbsp; 
      write(handle, msg, strlen(msg)); <BR>
      <P>&nbsp;&nbsp; /* seek to the beginning of the file */ <BR>&nbsp;&nbsp; 
      lseek(handle, 0L, SEEK_SET); <BR>
      <P>&nbsp;&nbsp; /* <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reads chars from the 
      file until hit EOF <BR>&nbsp;&nbsp; */ <BR>&nbsp;&nbsp; do 
      <BR>&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read(handle, 
      &amp;ch, 1); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%c", ch); 
      <BR>&nbsp;&nbsp; } while (!eof(handle)); <BR>
      <P>&nbsp;&nbsp; close(handle); <BR>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; 
      <BR>&nbsp; <BR>
      <P>函数名: exec... <BR>功&nbsp; 能: 装入并运行其它程序的函数 <BR>用&nbsp; 法: int execl(char 
      *pathname, char *arg0, arg1, ..., argn, NULL); <BR>&nbsp;int execle(char 
      *pathname, char *arg0, arg1, ..., argn, NULL, <BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      char *envp[]); <BR>&nbsp;int execlp(char *pathname, char *arg0, arg1, .., 
      NULL); <BR>&nbsp;int execple(char *pathname, char *arg0, arg1, ..., NULL, 
      <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *envp[]); <BR>&nbsp;int execv(char 
      *pathname, char *argv[]); <BR>&nbsp;int execve(char *pathname, char 
      *argv[], char *envp[]); <BR>&nbsp;int execvp(char *pathname, char 
      *argv[]); <BR>&nbsp;int execvpe(char *pathname, char *argv[], char 
      *envp[]); <BR>程序例: <BR>
      <P>/* execv example */ <BR>#include &lt;process.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>#include &lt;errno.h&gt; <BR>
      <P>void main(int argc, char *argv[]) <BR>{ <BR>&nbsp;&nbsp; int i; <BR>
      <P>&nbsp;&nbsp; printf("Command line arguments:\n"); <BR>&nbsp;&nbsp; for 
      (i=0; i&lt;argc; i++) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("[%2d] : 
      %s\n", i, argv[i]); <BR>
      <P>&nbsp;&nbsp; printf("About to exec child with arg1 arg2 ...\n"); 
      <BR>&nbsp;&nbsp; execv("CHILD.EXE", argv); <BR>
      <P>&nbsp;&nbsp; perror("exec error"); <BR>
      <P>&nbsp;&nbsp; exit(1); <BR>} <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: exit <BR>功&nbsp; 能: 终止程序 <BR>用&nbsp; 法: void exit(int status); 
      <BR>程序例: <BR>
      <P>#include &lt;stdlib.h&gt; <BR>#include &lt;conio.h&gt; <BR>#include 
      &lt;stdio.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; int status; <BR>
      <P>&nbsp;&nbsp; printf("Enter either 1 or 2\n"); <BR>&nbsp;&nbsp; status = 
      getch(); <BR>&nbsp;&nbsp; /* Sets DOS errorlevel&nbsp; */ <BR>&nbsp;&nbsp; 
      exit(status - '0'); <BR>
      <P>/* Note: this line is never reached */ <BR>&nbsp;&nbsp; return 0; <BR>} 
      <BR>&nbsp; <BR>&nbsp; <BR>
      <P>函数名: exp <BR>功&nbsp; 能: 指数函数 <BR>用&nbsp; 法: double exp(double x); 
      <BR>程序例: <BR>
      <P>#include &lt;stdio.h&gt; <BR>#include &lt;math.h&gt; <BR>
      <P>int main(void) <BR>{ <BR>&nbsp;&nbsp; double result; <BR>&nbsp;&nbsp; 
      double x = 4.0; <BR>
      <P>&nbsp;&nbsp; result = exp(x); <BR>&nbsp;&nbsp; printf("'e' raised to 
      the power \ <BR>&nbsp;&nbsp; of %lf (e ^ %lf) = %lf\n", <BR>&nbsp;&nbsp; 
      x, x, result); <BR>
      <P>&nbsp;&nbsp; return 0; <BR>} <BR>&nbsp; <BR>
      <HR width="94%" color=#ee9b73 SIZE=1>
    </TD>
    <TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A 
      href="http://www.hjflying.8u8.com/cl/025.htm">后一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/023.htm">前一页</A><BR><A 
      href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A 
      href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

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