|
Turbo C 2.0、Borland C++库函数及用例(33) } 函数名: freopen 功 能: 替换一个流 用 法: FILE *freopen( char *filename, char *type, FILE *stream ); 程序例:#include <stdio.h>int main(void) { /* redirect standard output to a file */ if (freopen("OUTPUT.FIL", "w", stdout) == NULL) fprintf(stderr, "error redirecting\ stdout\n"); /* this output will go to a file */ printf("This will go into a file."); /* close the standard output stream */ fclose(stdout); return 0; } 函数名: frexp 功 能: 把一个双精度数分解为尾数的指数 用 法: double frexp(double value, int *eptr); 程序例:#include <math.h> #include <stdio.h>int main(void) { double mantissa, number; int exponent; number = 8.0; mantissa = frexp(number, &exponent); printf("The number %lf is ", number); printf("%lf times two to the ", mantissa); printf("power of %d\n", exponent); return 0; } 函数名: fscanf 功 能: 从一个流中执行格式化输入 用 法: int fscanf( FILE *stream, char *format[,argument...] ); 程序例:#include <stdlib.h> #include <stdio.h>int main(void) { int i; printf("Input an integer: "); /* read an integer from the standard input stream */ if (fscanf(stdin, "%d", &i)) printf("The integer read was: %i\n", i); else { fprintf(stderr, "Error reading an \ integer from stdin.\n"); exit(1); } return 0; } 函数名: fseek 功 能: 重定位流上的文件指针 用 法: int fseek(FILE *stream,long offset,int fromwhere); 程序例:#include <stdio.h>long filesize(FILE *stream);int main(void) { FILE *stream; stream = fopen("MYFILE.TXT", "w+"); fprintf(stream, "This is a test"); printf("Filesize of MYFILE.TXT is %ld bytes\n\ ", filesize(stream)); fclose(stream); return 0; }long filesize(FILE *stream) { long curpos, length; curpos = ftell(stream); fseek(stream, 0L, SEEK_END); length = ftell(stream); fseek(stream, curpos, SEEK_SET); return length; } 函数名: fsetpos 功 能: 定位流上的文件指针 用 法: int fsetpos(FILE *stream, const fpos_t *pos); 程序例:#include <stdlib.h>
|