|
Turbo C 2.0、Borland C++库函数及用例(30) 功 能: 向下舍入 用 法: double floor(double x); 程序例:#include <stdio.h> #include <math.h>int main(void) { double number = 123.54; double down, up; down = floor(number); up = ceil(number); printf("original number %10.2lf\n", number); printf("number rounded down %10.2lf\n", down); printf("number rounded up %10.2lf\n", up); return 0; } 函数名: flushall 功 能: 清除所有缓冲区 用 法: int flushall(void); 程序例:#include <stdio.h>int main(void) { FILE *stream; /* create a file */ stream = fopen("DUMMY.FIL", "w"); /* flush all open streams */ printf("%d streams were flushed.\n", flushall()); /* close the file */ fclose(stream); return 0; } 函数名: fmod 功 能: 计算x对y的模, 即x/y的余数 用 法: double fmod(double x, double y); 程序例:#include <stdio.h> #include <math.h>int main(void) { double x = 5.0, y = 2.0; double result; result = fmod(x,y); printf("The remainder of (%lf / %lf) is \ %lf\n", x, y, result); return 0; } 函数名: fnmerge 功 能: 建立新文件名 用 法: void fnerge(char *path, char *drive, char *dir); 程序例:#include <string.h> #include <stdio.h> #include <dir.h>int main(void) { char s[MAXPATH]; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT]; getcwd(s,MAXPATH); /*get the current working directory*/ strcat(s,"\\"); /*append on a trailing character*/ fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */ strcpy(file,"DATA"); strcpy(ext,".TXT"); fnmerge(s,drive,dir,file,ext); /* merge everything into one string */ puts(s); /* display resulting string */ return 0; } 函数名: fopen 功 能: 打开一个流 用 法: FILE *fopen(char *filename, char *type); 程序例:#include <stdlib.h> #include <stdio.h> #include <dir.h>int main(void) { char *s; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT]; int flags; s=getenv("COMSPEC");
|