|
Turbo C 2.0、Borland C++库函数及用例(20) DOS buffer */ close(duphandle); } 函数名: dup2 功 能: 复制文件句柄 用 法: int dup2(int oldhandle, int newhandle); 程序例:#include <sys\stat.h> #include <string.h> #include <fcntl.h> #include <io.h>int main(void) { #define STDOUT 1 int nul, oldstdout; char msg[] = "This is a test"; /* create a file */ nul = open("DUMMY.FIL", O_CREAT O_RDWR, S_IREAD S_IWRITE); /* 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); /* close the handle for DUMMY.FIL */ close(nul); /* will be redirected into DUMMY.FIL */ write(STDOUT, msg, strlen(msg)); /* restore original standard output handle */ dup2(oldstdout, STDOUT); /* close duplicate handle for STDOUT */ close(oldstdout); return 0; }字母E开头函数 函数名: ecvt 功 能: 把一个浮点数转换为字符串 用 法: char ecvt( double value, int ndigit, int *decpt, int *sign ); 程序例:#include <stdlib.h> #include <stdio.h> #include <conio.h>int main(void) { char *string; double value; int dec, sign; int ndig = 10; clrscr(); value = 9.876; string = ecvt(value, ndig, &dec, &sign); printf("string = %s dec = %d \ sign = %d\n", string, dec, sign); value = -123.45; ndig= 15; string = ecvt(value,ndig,&dec,&sign); printf("string = %s dec = %d sign = %d\n", string, dec, sign); value = 0.6789e5; /* scientific notation */ ndig = 5; string = ecvt(value,ndig,&dec,&sign); printf("string = %s dec = %d\ sign = %d\n", string, dec, sign); return 0; } 函数名: ellipse 功 能: 画一椭圆 用 法: void far ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius); 程序例:#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h>int main(void) { /* request auto detection */
|