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

📄 024.htm

📁 一个好的讲DSP中C语言编程的电子书
💻 HTM
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->E</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 E">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - E">

<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD CLASS="tt3" VALIGN="top" width="8%"  bgcolor="#e0e0e0"><strong><A HREF="025.htm">后一页</A><BR>
<A HREF="023.htm">前一页</A><BR>

<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">E</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
函数名: ecvt
<BR>功&nbsp; 能: 把一个浮点数转换为字符串
<BR>用&nbsp; 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
<BR>程序例:
<BR>
<P>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<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>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>
<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>
<BR>#include &lt;dos.h>
<BR>#include &lt;conio.h>
<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>
<BR>#include &lt;string.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;fcntl.h>
<BR>#include &lt;io.h>
<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>
<BR>#include &lt;stdio.h>
<BR>#include &lt;errno.h>
<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>
<BR>#include &lt;conio.h>
<BR>#include &lt;stdio.h>
<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>
<BR>#include &lt;math.h>
<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 color="#EE9B73" size="1" width="94%">

</TD>
<TD CLASS="tt3" VALIGN="bottom" width="8%"  bgcolor="#e0e0e0"><strong><A HREF="025.htm">后一页</A><BR>
<A HREF="023.htm">前一页</A><BR>

<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
</TR>
</table>
</BODY></HTML>

⌨️ 快捷键说明

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