|
Turbo C 2.0、Borland C++库函数及用例(35) 用 法: long ftell(FILE *stream); 程序例:#include <stdio.h>int main(void) { FILE *stream; stream = fopen("MYFILE.TXT", "w+"); fprintf(stream, "This is a test"); printf("The file pointer is at byte \ %ld\n", ftell(stream)); fclose(stream); return 0; } 函数名: fwrite 功 能: 写内容到流中 用 法: int fwrite( void *ptr, int size, int nitems, FILE *stream ); 程序例:#include <stdio.h>struct mystruct { int i; char ch; };int main(void) { FILE *stream; struct mystruct s; if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */ { fprintf(stderr, "Cannot open output file.\n"); return 1; } s.i = 0; s.ch = 'A'; fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */ fclose(stream); /* close file */ return 0; }字母G开头函数函数名: gcvt 功 能: 把浮点数转换成字符串 用 法: char *gcvt(double value, int ndigit, char *buf); 程序例:#include <stdlib.h> #include <stdio.h>int main(void) { char str[25]; double num; int sig = 5; /* significant digits */ /* a regular number */ num = 9.876; gcvt(num, sig, str); printf("string = %s\n", str); /* a negative number */ num = -123.4567; gcvt(num, sig, str); printf("string = %s\n", str); /* scientific notation */ num = 0.678e5; gcvt(num, sig, str); printf("string = %s\n", str); return(0); } 函数名: getarccoords 功 能: 取得最后一次调用arc的坐标 用 法: void far getarccoords ( struct arccoordstype far *arccoords ); 程序例:#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h>int main(void) {/* request auto detection */ int gdriver = DETECT, gmode, errorcode; struct arccoordstype arcinfo; int midx, midy; int stangle = 45, endangle = 270; char sstr[80], estr[80];/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "");/* read result of initialization */ errorcode = graphresult();/* an error occurred */ if (errorcode != grOk)
|