韩冰 发表于 2004-10-4 03:01

函数大全(e开头)

<P align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>
</P>


<P><FONT color=#ff0000>函数名: ecvt </FONT>
功 能: 把一个浮点数转换为字符串
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
程序例: </P>
<P><FONT color=#0000ff>#include <STDLIB.H>
#include <STDIO.H>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
char *string;
double value;
int dec, sign;
int ndig = 10; </FONT></P>
<P><FONT color=#0000ff>clrscr();
value = 9.876;
string = ecvt(value, ndig, &amp;dec, &amp;sign);
printf("string = %s dec = %d \
sign = %d\n", string, dec, sign); </FONT></P>
<P><FONT color=#0000ff>value = -123.45;
ndig= 15;
string = ecvt(value,ndig,&amp;dec,&amp;sign);
printf("string = %s dec = %d sign = %d\n",
string, dec, sign);
</FONT></P>
<P><FONT color=#0000ff>value = 0.6789e5; /* scientific
notation */
ndig = 5;
string = ecvt(value,ndig,&amp;dec,&amp;sign);
printf("string = %s dec = %d\
sign = %d\n", string, dec, sign); </FONT></P>
<P><FONT color=#0000ff>return 0;
} </FONT>

</P>
<P><FONT color=#ff0000>函数名: ellipse </FONT>
功 能: 画一椭圆
用 法: void far ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
程序例: </P>
<P><FONT color=#0000ff>#include <GRAPHICS.H>
#include <STDLIB.H>
#include <STDIO.H>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 0, endangle = 360;
int xradius = 100, yradius = 50; </FONT></P>
<P><FONT color=#0000ff>/* initialize graphics, local variables */
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
<P><FONT color=#0000ff>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
/* terminate with an error code */
} </FONT></P>
<P><FONT color=#0000ff>midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor()); </FONT></P>
<P><FONT color=#0000ff>/* draw ellipse */
ellipse(midx, midy, stangle, endangle,
xradius, yradius); </FONT></P>
<P><FONT color=#0000ff>/* clean up */
getch();
closegraph();
return 0;
} </FONT>

</P>
<P><FONT color=#ff0000>函数名: enable </FONT>
功 能: 开放硬件中断
用 法: void enable(void);
程序例: </P>
<P><FONT color=#0000ff>/* ** NOTE:
This is an interrupt service routine. You can NOT compile this program
with Test Stack Overflow turned on and get an executable file which will
operate correctly.
*/ </FONT></P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <DOS.H>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>/* The clock tick interrupt */
#define INTR 0X1C </FONT></P>
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
<P><FONT color=#0000ff>int count=0; </FONT></P>
<P><FONT color=#0000ff>void interrupt handler(void)
{
/*
disable interrupts during the handling of the interrupt
*/
disable();
/* increase the global counter */
count++;
/*
re enable interrupts at the end of the handler
*/
enable();
/* call the old routine */
oldhandler();
} </FONT></P>
<P><FONT color=#0000ff>int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR); </FONT></P>
<P><FONT color=#0000ff>/* install the new interrupt handler */
setvect(INTR, handler); </FONT></P>
<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
while (count &lt; 20)
printf("count is %d\n",count); </FONT></P>
<P><FONT color=#0000ff>/* reset the old interrupt handler */
setvect(INTR, oldhandler); </FONT></P>
<P><FONT color=#0000ff>return 0;
} </FONT>

</P>
<P><FONT color=#ff0000>函数名: eof </FONT>
功 能: 检测文件结束
用 法: int eof(int *handle);
程序例: </P>
<P><FONT color=#0000ff>#include <SYS\STAT.H>
#include <STRING.H>
#include <STDIO.H>
#include <FCNTL.H>
#include <IO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int handle;
char msg[] = "This is a test";
char ch; </FONT></P>
<P><FONT color=#0000ff>/* create a file */
handle = open("DUMMY.FIL",
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE); </FONT></P>
<P><FONT color=#0000ff>/* write some data to the file */
write(handle, msg, strlen(msg)); </FONT></P>
<P><FONT color=#0000ff>/* seek to the beginning of the file */
lseek(handle, 0L, SEEK_SET); </FONT></P>
<P><FONT color=#0000ff>/*
reads chars from the file until hit EOF
*/
do
{
read(handle, &amp;ch, 1);
printf("%c", ch);
} while (!eof(handle)); </FONT></P>
<P><FONT color=#0000ff>close(handle);
return 0;
}
</FONT>
</P>
<P><FONT color=#ff0000>函数名: exec... </FONT>
功 能: 装入并运行其它程序的函数
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
char *envp[]);
int execlp(char *pathname, char *arg0, arg1, .., NULL);
int execple(char *pathname, char *arg0, arg1, ..., NULL,
char *envp[]);
int execv(char *pathname, char *argv[]);
int execve(char *pathname, char *argv[], char *envp[]);
int execvp(char *pathname, char *argv[]);
int execvpe(char *pathname, char *argv[], char *envp[]);
程序例: </P>
<P><FONT color=#0000ff>/* execv example */
#include <PROCESS.H>
#include <STDIO.H>
#include <ERRNO.H></FONT></P>
<P><FONT color=#0000ff>void main(int argc, char *argv[])
{
int i; </FONT></P>
<P><FONT color=#0000ff>printf("Command line arguments:\n");
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
execv("CHILD.EXE", argv); </FONT></P>
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
<P><FONT color=#0000ff>exit(1);
}
</FONT>
</P>
<P><FONT color=#ff0000>函数名: exit </FONT>
功 能: 终止程序
用 法: void exit(int status);
程序例: </P>
<P><FONT color=#0000ff>#include <STDLIB.H>
#include <CONIO.H>
#include <STDIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int status; </FONT></P>
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
status = getch();
/* Sets DOS errorlevel */
exit(status - '0'); </FONT></P>
<P><FONT color=#0000ff>/* Note: this line is never reached */
return 0;
}
</FONT>
</P>
<P><FONT color=#ff0000>函数名: exp </FONT>
功 能: 指数函数
用 法: double exp(double x);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <MATH.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
double result;
double x = 4.0; </FONT></P>
<P><FONT color=#0000ff>result = exp(x);
printf("'e' raised to the power \
of %lf (e ^ %lf) = %lf\n",
x, x, result); </FONT></P>
<P><FONT color=#0000ff>return 0;
}
</FONT></P>

韩冰 发表于 2004-10-4 03:02

<P align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(d开头)</FONT></B></FONT>
</P>
<p><P><FONT color=#ff0000>函数名: delay </FONT>
功 能: 将程序的执行暂停一段时间(毫秒)
用 法: void delay(unsigned milliseconds);
程序例:
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
sound(440);
delay(500);
nosound(); </FONT></P><P><FONT color=#0000ff>return 0;
}

</FONT></P><P><FONT color=#ff0000>函数名: delline </FONT>
功 能: 在文本窗口中删去一行
用 法: void delline(void);
程序例: </P><P><FONT color=#0000ff>#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
clrscr();
cprintf("The function DELLINE deletes \
the line containing the\r\n");
cprintf("cursor and moves all lines \
below it one line up.\r\n");
cprintf("DELLINE operates within the \
currently active text\r\n");
cprintf("window. Press any key to \
continue . . .");
gotoxy(1,2); /* Move the cursor to the
second line and first column */
getch(); </FONT></P><P><FONT color=#0000ff>delline();
getch(); </FONT></P><P><FONT color=#0000ff>return 0;
} </FONT>
</P><P><FONT color=#ff0000>函数名: detectgraph </FONT>
功 能: 通过检测硬件确定图形驱动程序和模式
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
#include <STDLIB.H>
#include <STDIO.H>
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>/* names of the various cards supported */
char *dname[] = { "requests detection",
"a CGA",
"an MCGA",
"an EGA",
"a 64K EGA",
"a monochrome EGA",
"an IBM 8514",
"a Hercules monochrome",
"an AT&amp;T 6300 PC",
"a VGA",
"an IBM 3270 PC"
}; </FONT></P><P><FONT color=#0000ff>int main(void)
{
/* returns detected hardware info. */
int gdriver, gmode, errorcode; </FONT></P><P><FONT color=#0000ff>/* detect graphics hardware available */
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><P><FONT color=#0000ff>/* read result of detectgraph call */
errorcode = graphresult();
if (errorcode != grOk) /* an error
occurred */
{
printf("Graphics error: %s\n", \
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error
code */
} </FONT></P><P><FONT color=#0000ff>/* display the information detected */
clrscr();
printf("You have %s video display \
card.\n", dname);
printf("Press any key to halt:");
getch();
return 0;
} </FONT>


</P><P><FONT color=#ff0000>函数名: difftime </FONT>
功 能: 计算两个时刻之间的时间差
用 法: double difftime(time_t time2, time_t time1);
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
#include <STDIO.H>
#include <DOS.H>
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
time_t first, second; </FONT></P><P><FONT color=#0000ff>clrscr();
first = time(NULL); /* Gets system
time */
delay(2000); /* Waits 2 secs */
second = time(NULL); /* Gets system time
again */ </FONT></P><P><FONT color=#0000ff>printf("The difference is: %f \
seconds\n",difftime(second,first));
getch(); </FONT></P><P><FONT color=#0000ff>return 0;
}
</FONT>
</P><P><FONT color=#ff0000>函数名: disable </FONT>
功 能: 屏蔽中断
用 法: void disable(void);
程序例: </P><P><FONT color=#0000ff>/***NOTE: This is an interrupt service
routine. You cannot compile this program
with Test Stack Overflow turned on and
get an executable file that operates
correctly. */ </FONT></P><P><FONT color=#0000ff>#include <STDIO.H>
#include <DOS.H>
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
interrupt */ </FONT></P><P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P><P><FONT color=#0000ff>int count=0; </FONT></P><P><FONT color=#0000ff>void interrupt handler(void)
{
/* disable interrupts during the handling of
the interrupt */
disable();
/* increase the global counter */
count++;
/* reenable interrupts at the end of the
handler */
enable();
/* call the old routine */
oldhandler();
} </FONT></P><P><FONT color=#0000ff>int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
while (count &lt; 20)
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
功 能: 将两个整数相除, 返回商和余数
用 法: div_t (int number, int denom);
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)
{
x = div(10,3);
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
}
</FONT>
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
功 能: 获取扩展DOS错误信息
用 法: int dosexterr(struct DOSERR *dblkp);
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
FILE *fp;
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
if (!fp) perror("Unable to open file for
reading");
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
information:\n");
printf(" Extended error: \
%d\n",info.exterror);
printf(" Class: \
%x\n",info.class);
printf(" Action: \
%x\n",info.action);
printf(" Error Locus: \
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
} </FONT>

</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
功 能: 转换日期和时间为UNIX时间格式
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
#include <STDDEF.H>
#include <DOS.H>
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
time_t t;
struct time d_time;
struct date d_date;
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
local = localtime(&amp;t);
printf("Time and Date: %s\n", \
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
} </FONT>

</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
功 能: 画多边形
用 法: void far drawpoly(int numpoints, int far *polypoints);
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
#include <STDLIB.H>
#include <STDIO.H>
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
int poly; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
variables */
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n", \
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
/* terminate with an error code */
exit(1);
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly = 20; /* 1st vertext */
poly = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly = maxx - 20; /* 2nd */
poly = 20; </FONT></P><P><FONT color=#0000ff>poly = maxx - 50; /* 3rd */
poly = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly = maxx / 2; /* 4th */
poly = maxy / 2;
/*
drawpoly doesn't automatically close
the polygon, so we close it.
*/
poly = poly;
poly = poly; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
getch();
closegraph();
return 0;
}
</FONT>
</P><P><FONT color=#ff0000>函数名: dup </FONT>
功 能: 复制一个文件句柄
用 法: int dup(int handle);
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
#include <STDIO.H>
#include <CONIO.H>
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
{
FILE *fp;
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
printf("Press any key to flush \
DUMMY.FIL:");
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
closing it */
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
key to quit:");
getch();
return 0;
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
{
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
DOS buffer */
close(duphandle);
}

</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
功 能: 复制文件句柄
用 法: int dup2(int oldhandle, int newhandle);
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
#include <STRING.H>
#include <FCNTL.H>
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
{
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
output */
oldstdout = dup(STDOUT);
/*
redirect standard output to DUMMY.FIL
by duplicating the file handle onto the
file handle for standard output.
*/
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
handle */
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
}
</FONT></P>
页: [1]
查看完整版本: 函数大全(e开头)