|
Turbo C 2.0、Borland C++库函数及用例(25) fopen("DUMMY.TWO", "w"); /* close the open streams */ streams_closed = fcloseall(); if (streams_closed == EOF) /* issue an error message */ perror("Error"); else /* print result of fcloseall() function */ printf("%d streams were closed.\n", streams_closed); return 0; } 函数名: fcvt 功 能: 把一个浮点数转换为字符串 用 法: char *fcvt( 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; } 函数名: fdopen 功 能: 把流与一个文件句柄相接 用 法: FILE *fdopen(int handle, char *type); 程序例:#include <sys\stat.h> #include <stdio.h> #include <fcntl.h> #include <io.h>int main(void) { int handle; FILE *stream; /* open a file */ handle = open("DUMMY.FIL", O_CREAT, S_IREAD S_IWRITE); /* now turn the handle into a stream */ stream = fdopen(handle, "w"); if (stream == NULL) printf("fdopen failed\n"); else { fprintf(stream, "Hello world\n"); fclose(stream); } return 0; } 函数名: feof 功 能: 检测流上的文件结束符 用 法: int feof(FILE *stream); 程序例:#include <stdio.h>int main(void) { FILE *stream; /* open a file for reading */ stream = fopen("DUMMY.FIL", "r"); /* read a character from the file */ fgetc(stream); /* check for EOF */ if (feof(stream)) printf("We have reached end-of-file\n"); /* close the file */ fclose(stream); return 0;
|