📄 王大刚--c语言编程宝典--e.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>功 能: 把一个浮点数转换为字符串 <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 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 + -