📄 024.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>功 能: 把一个浮点数转换为字符串
<BR>用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
<BR>程序例:
<BR>
<P>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> char *string;
<BR> double value;
<BR> int dec, sign;
<BR> int ndig = 10;
<BR>
<P> clrscr();
<BR> value = 9.876;
<BR> string = ecvt(value, ndig, &dec, &sign);
<BR> printf("string = %s dec
= %d \
<BR> sign = %d\n", string, dec, sign);
<BR>
<P> value = -123.45;
<BR> ndig= 15;
<BR> string = ecvt(value,ndig,&dec,&sign);
<BR> printf("string = %s dec = %d sign = %d\n",
<BR> string, dec, sign);
<BR>
<BR>
<P> value = 0.6789e5; /* scientific
<BR> notation */
<BR> ndig = 5;
<BR> string = ecvt(value,ndig,&dec,&sign);
<BR> printf("string = %s
dec = %d\
<BR> sign = %d\n", string, dec, sign);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: ellipse
<BR>功 能: 画一椭圆
<BR>用 法: void far ellipse(int x, int y, int stangle, int endangle,
<BR> int xradius, int yradius);
<BR>程序例:
<BR>
<P>#include <graphics.h>
<BR>#include <stdlib.h>
<BR>#include <stdio.h>
<BR>#include <conio.h>
<BR>
<P>int main(void)
<BR>{
<BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy;
<BR> int stangle = 0, endangle = 360;
<BR> int xradius = 100, yradius = 50;
<BR>
<P> /* initialize graphics, local variables */
<BR> initgraph(&gdriver, &gmode, "");
<BR>
<P> /* read result of initialization */
<BR> errorcode = graphresult();
<BR> if (errorcode != grOk)
<BR> /* an error occurred */
<BR> {
<BR> printf("Graphics error: %s\n",
<BR> grapherrormsg(errorcode));
<BR> printf("Press any key to halt:");
<BR> getch();
<BR> exit(1);
<BR> /* terminate with an error code */
<BR> }
<BR>
<P> midx = getmaxx() / 2;
<BR> midy = getmaxy() / 2;
<BR> setcolor(getmaxcolor());
<BR>
<P> /* draw ellipse */
<BR> ellipse(midx, midy, stangle, endangle,
<BR> xradius, yradius);
<BR>
<P> /* clean up */
<BR> getch();
<BR> closegraph();
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: enable
<BR>功 能: 开放硬件中断
<BR>用 法: 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 <stdio.h>
<BR>#include <dos.h>
<BR>#include <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> disable interrupts during the handling of the interrupt
<BR>*/
<BR> disable();
<BR>/* increase the global counter */
<BR> count++;
<BR>/*
<BR> re enable interrupts at the end of the handler
<BR>*/
<BR> enable();
<BR>/* call the old routine */
<BR> oldhandler();
<BR>}
<BR>
<P>int main(void)
<BR>{
<BR>/* save the old interrupt vector */
<BR> oldhandler = getvect(INTR);
<BR>
<P>/* install the new interrupt handler */
<BR> setvect(INTR, handler);
<BR>
<P>/* loop until the counter exceeds 20 */
<BR> while (count < 20)
<BR> printf("count is %d\n",count);
<BR>
<P>/* reset the old interrupt handler */
<BR> setvect(INTR, oldhandler);
<BR>
<P> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: eof
<BR>功 能: 检测文件结束
<BR>用 法: int eof(int *handle);
<BR>程序例:
<BR>
<P>#include <sys\stat.h>
<BR>#include <string.h>
<BR>#include <stdio.h>
<BR>#include <fcntl.h>
<BR>#include <io.h>
<BR>
<P>int main(void)
<BR>{
<BR> int handle;
<BR> char msg[] = "This is a test";
<BR> char ch;
<BR>
<P> /* create a file */
<BR> handle = open("DUMMY.FIL",
<BR> O_CREAT | O_RDWR,
<BR> S_IREAD | S_IWRITE);
<BR>
<P> /* write some data to the file */
<BR> write(handle, msg, strlen(msg));
<BR>
<P> /* seek to the beginning of the file */
<BR> lseek(handle, 0L, SEEK_SET);
<BR>
<P> /*
<BR> reads chars from the file until hit
EOF
<BR> */
<BR> do
<BR> {
<BR> read(handle, &ch, 1);
<BR> printf("%c", ch);
<BR> } while (!eof(handle));
<BR>
<P> close(handle);
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: exec...
<BR>功 能: 装入并运行其它程序的函数
<BR>用 法: int execl(char *pathname, char *arg0, arg1, ..., argn,
NULL);
<BR> int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
<BR> char *envp[]);
<BR> int execlp(char *pathname, char *arg0, arg1, .., NULL);
<BR> int execple(char *pathname, char *arg0, arg1, ..., NULL,
<BR> char *envp[]);
<BR> int execv(char *pathname, char *argv[]);
<BR> int execve(char *pathname, char *argv[], char *envp[]);
<BR> int execvp(char *pathname, char *argv[]);
<BR> int execvpe(char *pathname, char *argv[], char *envp[]);
<BR>程序例:
<BR>
<P>/* execv example */
<BR>#include <process.h>
<BR>#include <stdio.h>
<BR>#include <errno.h>
<BR>
<P>void main(int argc, char *argv[])
<BR>{
<BR> int i;
<BR>
<P> printf("Command line arguments:\n");
<BR> for (i=0; i<argc; i++)
<BR> printf("[%2d] : %s\n", i, argv[i]);
<BR>
<P> printf("About to exec child with arg1 arg2 ...\n");
<BR> execv("CHILD.EXE", argv);
<BR>
<P> perror("exec error");
<BR>
<P> exit(1);
<BR>}
<BR>
<BR>
<BR>
<P>函数名: exit
<BR>功 能: 终止程序
<BR>用 法: void exit(int status);
<BR>程序例:
<BR>
<P>#include <stdlib.h>
<BR>#include <conio.h>
<BR>#include <stdio.h>
<BR>
<P>int main(void)
<BR>{
<BR> int status;
<BR>
<P> printf("Enter either 1 or 2\n");
<BR> status = getch();
<BR> /* Sets DOS errorlevel */
<BR> exit(status - '0');
<BR>
<P>/* Note: this line is never reached */
<BR> return 0;
<BR>}
<BR>
<BR>
<BR>
<P>函数名: exp
<BR>功 能: 指数函数
<BR>用 法: double exp(double x);
<BR>程序例:
<BR>
<P>#include <stdio.h>
<BR>#include <math.h>
<BR>
<P>int main(void)
<BR>{
<BR> double result;
<BR> double x = 4.0;
<BR>
<P> result = exp(x);
<BR> printf("'e' raised to the power \
<BR> of %lf (e ^ %lf) = %lf\n",
<BR> x, x, result);
<BR>
<P> return 0;
<BR>}
<BR>
<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 + -