f.txt
Upload User: harvey99
Upload Date: 2020-01-11
Package Size: 938k
Code Size: 26k
Category:

Other Books

Development Platform:

CHM

  1. 函数名: fabs
  2. 功  能: 返回浮点数的绝对值
  3. 用  法: double fabs(double x);
  4. 程序例: 
  5. #include <stdio.h>
  6. #include <math.h>
  7. int main(void)
  8. {
  9.    float  number = -1234.0;
  10.    printf("number: %f  absolute value: %fn",
  11.    number, fabs(number));
  12.    return 0;
  13. }
  14.  
  15.  
  16.  
  17. 函数名: farcalloc
  18. 功  能: 从远堆栈中申请空间
  19. 用  法: void far *farcalloc(unsigned long units, unsigned ling unitsz);
  20. 程序例:
  21. #include <stdio.h>
  22. #include <alloc.h>
  23. #include <string.h>
  24. #include <dos.h>
  25. int main(void)
  26. {
  27.    char far *fptr;
  28.    char *str = "Hello";
  29.    /* allocate memory for the far pointer */
  30.    fptr = farcalloc(10, sizeof(char));
  31.    /* copy "Hello" into allocated memory */
  32.    /*
  33.       Note: movedata is used because you
  34.       might be in a small data model, in
  35.       which case a normal string copy routine
  36.       can not be used since it assumes the
  37.       pointer size is near.
  38.    */
  39.    movedata(FP_SEG(str), FP_OFF(str),
  40.      FP_SEG(fptr), FP_OFF(fptr),
  41.             strlen(str));
  42.    /* display string (note the F modifier) */
  43.    printf("Far string is: %Fsn", fptr);
  44.    /* free the memory */
  45.    farfree(fptr);
  46.    return 0;
  47. }
  48.  
  49.  
  50.  
  51. 函数名: farcoreleft
  52. 功  能: 返回远堆中未作用存储区大小
  53. 用  法: long farcoreleft(void);
  54. 程序例:
  55. #include <stdio.h>
  56. #include <alloc.h>
  57. int main(void)
  58. {
  59.    printf("The difference between the
  60.     highest allocated block in the
  61.            farn");
  62.    printf("heap and the top of the far heap
  63.            is: %lu bytesn", farcoreleft());
  64.    return 0;
  65. }
  66.  
  67.  
  68.  
  69. 函数名: farfree
  70. 功  能: 从远堆中释放一块
  71. 用  法: void farfree(void);
  72. 程序例:
  73. #include <stdio.h>
  74. #include <alloc.h>
  75. #include <string.h>
  76. #include <dos.h>
  77. int main(void)
  78. {
  79.    char far *fptr;
  80.    char *str = "Hello";
  81.    /* allocate memory for the far pointer */
  82.    fptr = farcalloc(10, sizeof(char));
  83.    /* copy "Hello" into allocated memory */
  84.    /*
  85.       Note: movedata is used because you might be in a small data model,
  86.       in which case a normal string copy routine can't be used since it
  87.       assumes the pointer size is near.
  88.    */
  89.    movedata(FP_SEG(str), FP_OFF(str),
  90.             FP_SEG(fptr), FP_OFF(fptr),
  91.             strlen(str));
  92.    /* display string (note the F modifier) */
  93.    printf("Far string is: %Fsn", fptr);
  94.    /* free the memory */
  95.    farfree(fptr);
  96.    return 0;
  97. }
  98.  
  99.  
  100.  
  101. 函数名: farmalloc
  102. 功  能: 从远堆中分配存储块
  103. 用  法: void far *farmalloc(unsigned long size);
  104. 程序例:
  105. #include <stdio.h>
  106. #include <alloc.h>
  107. #include <string.h>
  108. #include <dos.h>
  109. int main(void)
  110. {
  111.    char far *fptr;
  112.    char *str = "Hello";
  113.    /* allocate memory for the far pointer */
  114.    fptr = farmalloc(10);
  115.    /* copy "Hello" into allocated memory */
  116.    /*
  117.       Note: movedata is used because we might
  118.       be in a small data model, in which case
  119.       a normal string copy routine can not be
  120.       used since it assumes the pointer size
  121.       is near.
  122.    */
  123.    movedata(FP_SEG(str), FP_OFF(str),
  124.      FP_SEG(fptr), FP_OFF(fptr),
  125.      strlen(str));
  126.    /* display string (note the F modifier) */
  127.    printf("Far string is: %Fsn", fptr);
  128.    /* free the memory */
  129.    farfree(fptr);
  130.    return 0;
  131. }
  132.  
  133.  
  134.  
  135. 函数名: farrealloc
  136. 功  能: 调整远堆中的分配块
  137. 用  法: void far *farrealloc(void far *block, unsigned long newsize);
  138. 程序例:
  139. #include <stdio.h>
  140. #include <alloc.h>
  141. int main(void)
  142. {
  143.    char far *fptr;
  144.    fptr = farmalloc(10);
  145.    printf("First address: %Fpn", fptr);
  146.    fptr = farrealloc(fptr,20);
  147.    printf("New address  : %Fpn", fptr);
  148.    farfree(fptr);
  149.    return 0;
  150. }
  151.  
  152.  
  153. 函数名: fclose
  154. 功  能: 关闭一个流
  155. 用  法: int fclose(FILE *stream);
  156. 程序例:
  157. #include <string.h>
  158. #include <stdio.h>
  159. int main(void)
  160. {
  161.    FILE *fp;
  162.    char buf[11] = "0123456789";
  163.    /* create a file containing 10 bytes */
  164.    fp = fopen("DUMMY.FIL", "w");
  165.    fwrite(&buf, strlen(buf), 1, fp);
  166.    /* close the file */
  167.    fclose(fp);
  168.    return 0;
  169. }
  170.  
  171.  
  172.  
  173. 函数名: fcloseall
  174. 功  能: 关闭打开流
  175. 用  法: int fcloseall(void);
  176. 程序例:
  177. #include <stdio.h>
  178. int main(void)
  179. {
  180.    int streams_closed;
  181.    /* open two streams */
  182.    fopen("DUMMY.ONE", "w");
  183.    fopen("DUMMY.TWO", "w");
  184.    /* close the open streams */
  185.    streams_closed = fcloseall();
  186.    if (streams_closed == EOF)
  187.       /* issue an error message */
  188.       perror("Error");
  189.    else
  190.       /* print result of fcloseall() function */
  191.       printf("%d streams were closed.n", streams_closed);
  192.    return 0;
  193. }
  194.  
  195.  
  196. 函数名: fcvt
  197. 功  能: 把一个浮点数转换为字符串
  198. 用  法: char *fcvt(double value, int ndigit, int *decpt, int *sign);
  199. 程序例:
  200. #include <stdlib.h>
  201. #include <stdio.h>
  202. #include <conio.h>
  203. int main(void)
  204. {
  205.    char *string;
  206.    double value;
  207.    int dec, sign;
  208.    int ndig = 10;
  209.    clrscr();
  210.    value = 9.876;
  211.    string = ecvt(value, ndig, &dec, &sign);
  212.    printf("string = %s      dec = %d 
  213.           sign = %dn", string, dec, sign);
  214.    value = -123.45;
  215.    ndig= 15;
  216.    string = ecvt(value,ndig,&dec,&sign);
  217.    printf("string = %s dec = %d sign = %dn",
  218.           string, dec, sign);
  219.  
  220.    value = 0.6789e5; /* scientific
  221.                         notation */
  222.    ndig = 5;
  223.    string = ecvt(value,ndig,&dec,&sign);
  224.    printf("string = %s           dec = %d
  225.           sign = %dn", string, dec, sign);
  226.    return 0;
  227. }
  228.  
  229.  
  230.  
  231. 函数名: fdopen
  232. 功  能: 把流与一个文件句柄相接
  233. 用  法: FILE *fdopen(int handle, char *type);
  234. 程序例:
  235. #include <sysstat.h>
  236. #include <stdio.h>
  237. #include <fcntl.h>
  238. #include <io.h>
  239. int main(void)
  240. {
  241.    int handle;
  242.    FILE *stream;
  243.    /* open a file */
  244.    handle = open("DUMMY.FIL", O_CREAT,
  245.     S_IREAD | S_IWRITE);
  246.    /* now turn the handle into a stream */
  247.    stream = fdopen(handle, "w");
  248.    if (stream == NULL)
  249.       printf("fdopen failedn");
  250.    else
  251.    {
  252.       fprintf(stream, "Hello worldn");
  253.       fclose(stream);
  254.    }
  255.    return 0;
  256. }
  257.  
  258.  
  259. 函数名: feof
  260. 功  能: 检测流上的文件结束符
  261. 用  法: int feof(FILE *stream);
  262. 程序例:
  263. #include <stdio.h>
  264. int main(void)
  265. {
  266.    FILE *stream;
  267.    /* open a file for reading */
  268.    stream = fopen("DUMMY.FIL", "r");
  269.    /* read a character from the file */
  270.    fgetc(stream);
  271.    /* check for EOF */
  272.    if (feof(stream))
  273.       printf("We have reached end-of-filen");
  274.    /* close the file */
  275.    fclose(stream);
  276.    return 0;
  277. }
  278.  
  279.  
  280. 函数名: ferror
  281. 功  能: 检测流上的错误
  282. 用  法: int ferror(FILE *stream);
  283. 程序例:
  284. #include <stdio.h>
  285. int main(void)
  286. {
  287.    FILE *stream;
  288.    /* open a file for writing */
  289.    stream = fopen("DUMMY.FIL", "w");
  290.    /* force an error condition by attempting to read */
  291.    (void) getc(stream);
  292.    if (ferror(stream))  /* test for an error on the stream */
  293.    {
  294.       /* display an error message */
  295.       printf("Error reading from DUMMY.FILn");
  296.       /* reset the error and EOF indicators */
  297.       clearerr(stream);
  298.    }
  299.    fclose(stream);
  300.    return 0;
  301. }
  302.  
  303.  
  304.  
  305. 函数名: fflush
  306. 功  能: 清除一个流
  307. 用  法: int fflush(FILE *stream);
  308. 程序例:
  309. #include <string.h>
  310. #include <stdio.h>
  311. #include <conio.h>
  312. #include <io.h>
  313. void flush(FILE *stream);
  314. int main(void)
  315. {
  316.    FILE *stream;
  317.    char msg[] = "This is a test";
  318.    /* create a file */
  319.    stream = fopen("DUMMY.FIL", "w");
  320.    /* write some data to the file */
  321.    fwrite(msg, strlen(msg), 1, stream);
  322.    clrscr();
  323.    printf("Press any key to flush
  324.    DUMMY.FIL:");
  325.    getch();
  326.    /* flush the data to DUMMY.FIL without
  327.       closing it */
  328.    flush(stream);
  329.    printf("nFile was flushed, Press any key
  330.    to quit:");
  331.    getch();
  332.    return 0;
  333. }
  334. void flush(FILE *stream)
  335. {
  336.      int duphandle;
  337.      /* flush the stream's internal buffer */
  338.      fflush(stream);
  339.      /* make a duplicate file handle */
  340.      duphandle = dup(fileno(stream));
  341.      /* close the duplicate handle to flush
  342.         the DOS buffer */
  343.      close(duphandle);
  344. }
  345.  
  346.  
  347.  
  348. 函数名: fgetc
  349. 功  能: 从流中读取字符
  350. 用  法: int fgetc(FILE *stream);
  351. 程序例:
  352. #include <string.h>
  353. #include <stdio.h>
  354. #include <conio.h>
  355. int main(void)
  356. {
  357.    FILE *stream;
  358.    char string[] = "This is a test";
  359.    char ch;
  360.    /* open a file for update */
  361.    stream = fopen("DUMMY.FIL", "w+");
  362.    /* write a string into the file */
  363.    fwrite(string, strlen(string), 1, stream);
  364.    /* seek to the beginning of the file */
  365.    fseek(stream, 0, SEEK_SET);
  366.    do
  367.    {
  368.       /* read a char from the file */
  369.       ch = fgetc(stream);
  370.       /* display the character */
  371.       putch(ch);
  372.    } while (ch != EOF);
  373.    fclose(stream);
  374.    return 0;
  375. }
  376.  
  377.  
  378.  
  379. 函数名: fgetchar
  380. 功  能: 从流中读取字符
  381. 用  法: int fgetchar(void);
  382. 程序例:
  383. #include <stdio.h>
  384. int main(void)
  385. {
  386.    char ch;
  387.    /* prompt the user for input */
  388.    printf("Enter a character followed by 
  389.    <Enter>: ");
  390.    /* read the character from stdin */
  391.    ch = fgetchar();
  392.    /* display what was read */
  393.    printf("The character read is: '%c'n",
  394.           ch);
  395.    return 0;
  396. }
  397.  
  398.  
  399.  
  400. 函数名: fgetpos
  401. 功  能: 取得当前文件的句柄
  402. 用  法: int fgetpos(FILE *stream);
  403. 程序例:
  404. #include <string.h>
  405. #include <stdio.h>
  406. int main(void)
  407. {
  408.    FILE *stream;
  409.    char string[] = "This is a test";
  410.    fpos_t filepos;
  411.    /* open a file for update */
  412.    stream = fopen("DUMMY.FIL", "w+");
  413.    /* write a string into the file */
  414.    fwrite(string, strlen(string), 1, stream);
  415.    /* report the file pointer position */
  416.    fgetpos(stream, &filepos);
  417.    printf("The file pointer is at byte
  418.           %ldn", filepos);
  419.    fclose(stream);
  420.    return 0;
  421. }
  422.  
  423.  
  424.  
  425. 函数名: fgets
  426. 功  能: 从流中读取一字符串
  427. 用  法: char *fgets(char *string, int n, FILE *stream);
  428. 程序例:
  429. #include <string.h>
  430. #include <stdio.h>
  431. int main(void)
  432. {
  433.    FILE *stream;
  434.    char string[] = "This is a test";
  435.    char msg[20];
  436.    /* open a file for update */
  437.    stream = fopen("DUMMY.FIL", "w+");
  438.    /* write a string into the file */
  439.    fwrite(string, strlen(string), 1, stream);
  440.    /* seek to the start of the file */
  441.    fseek(stream, 0, SEEK_SET);
  442.    /* read a string from the file */
  443.    fgets(msg, strlen(string)+1, stream);
  444.    /* display the string */
  445.    printf("%s", msg);
  446.    fclose(stream);
  447.    return 0;
  448. }
  449.  
  450.  
  451.  
  452. 函数名: filelength
  453. 功  能: 取文件长度字节数
  454. 用  法: long filelength(int handle);
  455. 程序例:
  456. #include <string.h>
  457. #include <stdio.h>
  458. #include <fcntl.h>
  459. #include <io.h>
  460. int main(void)
  461. {
  462.    int handle;
  463.    char buf[11] = "0123456789";
  464.    /* create a file containing 10 bytes */
  465.    handle = open("DUMMY.FIL", O_CREAT);
  466.    write(handle, buf, strlen(buf));
  467.    /* display the size of the file */
  468.    printf("file length in bytes: %ldn",
  469.    filelength(handle));
  470.    /* close the file */
  471.    close(handle);
  472.    return 0;
  473. }
  474.  
  475.  
  476. 函数名: fillellipse
  477. 功  能: 画出并填充一椭圆
  478. 用  法: void far fillellipse(int x, int y, int xradius, int yradius);
  479. 程序例:
  480. #include <graphics.h>
  481. #include <conio.h>
  482. int main(void)
  483. {
  484.    int gdriver = DETECT, gmode;
  485.    int xcenter, ycenter, i;
  486.    initgraph(&gdriver,&gmode,"");
  487.    xcenter = getmaxx() / 2;
  488.    ycenter = getmaxy() / 2;
  489.    for (i=0; i<13; i++)
  490.    {
  491.       setfillstyle(i,WHITE);
  492.       fillellipse(xcenter,ycenter,100,50);
  493.       getch();
  494.    }
  495.    closegraph();
  496.    return 0;
  497. }
  498.  
  499.  
  500.  
  501. 函数名: fillpoly
  502. 功  能: 画并填充一个多边形
  503. 用  法: void far fillpoly(int numpoints, int far *polypoints);
  504. 程序例:
  505. #include <graphics.h>
  506. #include <stdlib.h>
  507. #include <stdio.h>
  508. #include <conio.h>
  509. int main(void)
  510. {
  511.    /* request auto detection */
  512.    int gdriver = DETECT, gmode, errorcode;
  513.    int i, maxx, maxy;
  514.    /* our polygon array */
  515.    int poly[8];
  516.    /* initialize graphics, local variables */
  517.    initgraph(&gdriver, &gmode, "");
  518.    /* read result of initialization */
  519.    errorcode = graphresult();
  520.    if (errorcode != grOk)
  521.    /* an error occurred */
  522.    {
  523.       printf("Graphics error: %sn",
  524.              grapherrormsg(errorcode));
  525.       printf("Press any key to halt:");
  526.       getch();
  527.       exit(1);
  528.       /* terminate with an error code */
  529.    }
  530.    maxx = getmaxx();
  531.    maxy = getmaxy();
  532.    poly[0] = 20;        /* 1st vertext */
  533.    poly[1] = maxy / 2;
  534.    poly[2] = maxx - 20; /* 2nd */
  535.    poly[3] = 20;
  536.    poly[4] = maxx - 50; /* 3rd */
  537.    poly[5] = maxy - 20;
  538.    /*
  539.       4th vertex. fillpoly automatically
  540.       closes the polygon.
  541.    */
  542.    poly[6] = maxx / 2;
  543.    poly[7] = maxy / 2;
  544.    /* loop through the fill patterns */
  545.    for (i=EMPTY_FILL; i<USER_FILL; i++)
  546.    {
  547.       /* set fill pattern */
  548.       setfillstyle(i, getmaxcolor());
  549.       /* draw a filled polygon */
  550.       fillpoly(4, poly);
  551.       getch();
  552.    }
  553.    /* clean up */
  554.    closegraph();
  555.    return 0;
  556. }
  557.  
  558.  
  559.  
  560. 函数名: findfirst, findnext
  561. 功  能: 搜索磁盘目录; 取得下一个匹配的findfirst模式的文件
  562. 用  法: int findfirst(char *pathname, struct ffblk *ffblk, int attrib);
  563.  int findnext(struct ffblk *ffblk);
  564. 程序例:
  565. /* findnext example */
  566. #include <stdio.h>
  567. #include <dir.h>
  568. int main(void)
  569. {
  570.    struct ffblk ffblk;
  571.    int done;
  572.    printf("Directory listing of *.*n");
  573.    done = findfirst("*.*",&ffblk,0);
  574.    while (!done)
  575.    {
  576.       printf("  %sn", ffblk.ff_name);
  577.       done = findnext(&ffblk);
  578.    }
  579.    return 0;
  580. }
  581.  
  582.  
  583.  
  584. 函数名: floodfill
  585. 功  能: 填充一个有界区域
  586. 用  法: void far floodfill(int x, int y, int border);
  587. 程序例:
  588. #include <graphics.h>
  589. #include <stdlib.h>
  590. #include <stdio.h>
  591. #include <conio.h>
  592. int main(void)
  593. {
  594.    /* request auto detection */
  595.    int gdriver = DETECT, gmode, errorcode;
  596.    int maxx, maxy;
  597.    /* initialize graphics, local variables */
  598.    initgraph(&gdriver, &gmode, "");
  599.    /* read result of initialization */
  600.    errorcode = graphresult();
  601.    if (errorcode != grOk)
  602.    /* an error occurred */
  603.    {
  604.       printf("Graphics error: %sn",
  605.              grapherrormsg(errorcode));
  606.       printf("Press any key to halt:");
  607.       getch();
  608.       exit(1);
  609.       /* terminate with an error code */
  610.    }
  611.    maxx = getmaxx();
  612.    maxy = getmaxy();
  613.    /* select drawing color */
  614.    setcolor(getmaxcolor());
  615.    /* select fill color */
  616.    setfillstyle(SOLID_FILL, getmaxcolor());
  617.    /* draw a border around the screen */
  618.    rectangle(0, 0, maxx, maxy);
  619.    /* draw some circles */
  620.    circle(maxx / 3, maxy /2, 50);
  621.    circle(maxx / 2, 20, 100);
  622.    circle(maxx-20, maxy-50, 75);
  623.    circle(20, maxy-20, 25);
  624.    /* wait for a key */
  625.    getch();
  626.    /* fill in bounded region */
  627.    floodfill(2, 2, getmaxcolor());
  628.    /* clean up */
  629.    getch();
  630.    closegraph();
  631.    return 0;
  632. }
  633.  
  634.  
  635.  
  636. 函数名: floor
  637. 功  能: 向下舍入
  638. 用  法: double floor(double x);
  639. 程序例:
  640. #include <stdio.h>
  641. #include <math.h>
  642. int main(void)
  643. {
  644.    double number = 123.54;
  645.    double down, up;
  646.    down = floor(number);
  647.    up = ceil(number);
  648.    printf("original number     %10.2lfn",
  649.           number);
  650.    printf("number rounded down %10.2lfn",
  651.           down);
  652.    printf("number rounded up   %10.2lfn",
  653.           up);
  654.    return 0;
  655. }
  656.  
  657.  
  658.  
  659. 函数名: flushall
  660. 功  能: 清除所有缓冲区
  661. 用  法: int flushall(void);
  662. 程序例:
  663. #include <stdio.h>
  664. int main(void)
  665. {
  666.    FILE *stream;
  667.    /* create a file */
  668.    stream = fopen("DUMMY.FIL", "w");
  669.    /* flush all open streams */
  670.    printf("%d streams were flushed.n",
  671.    flushall());
  672.    /* close the file */
  673.    fclose(stream);
  674.    return 0;
  675. }
  676.  
  677.  
  678.  
  679. 函数名: fmod
  680. 功  能: 计算x对y的模, 即x/y的余数
  681. 用  法: double fmod(double x, double y);
  682. 程序例:
  683. #include <stdio.h>
  684. #include <math.h>
  685. int main(void)
  686. {
  687.    double x = 5.0, y = 2.0;
  688.    double result;
  689.    result = fmod(x,y);
  690.    printf("The remainder of (%lf / %lf) is 
  691.           %lfn", x, y, result);
  692.    return 0;
  693. }
  694.  
  695.  
  696.  
  697. 函数名: fnmerge
  698. 功  能: 建立新文件名
  699. 用  法: void fnerge(char *path, char *drive, char *dir);
  700. 程序例:
  701. #include <string.h>
  702. #include <stdio.h>
  703. #include <dir.h>
  704.  
  705. int main(void)
  706. {
  707.     char s[MAXPATH];
  708.     char drive[MAXDRIVE];
  709.     char dir[MAXDIR];
  710.     char file[MAXFILE];
  711.     char ext[MAXEXT];
  712.     getcwd(s,MAXPATH);              /* get the current working directory */
  713.     strcat(s,"\");                  /* append on a trailing  character */
  714.     fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */
  715.     strcpy(file,"DATA");
  716.     strcpy(ext,".TXT");
  717.     fnmerge(s,drive,dir,file,ext);   /* merge everything into one string */
  718.     puts(s);                                 /* display resulting string */
  719.     return 0;
  720. }
  721.  
  722.  
  723.  
  724. 函数名: fopen
  725. 功  能: 打开一个流
  726. 用  法: FILE *fopen(char *filename, char *type);
  727. 程序例:
  728. #include <stdlib.h>
  729. #include <stdio.h>
  730. #include <dir.h>
  731. int main(void)
  732. {
  733.     char *s;
  734.     char drive[MAXDRIVE];
  735.     char dir[MAXDIR];
  736.     char file[MAXFILE];
  737.     char ext[MAXEXT];
  738.     int flags;
  739.     s=getenv("COMSPEC"); /* get the comspec environment parameter */
  740.     flags=fnsplit(s,drive,dir,file,ext);
  741.     printf("Command processor info:n");
  742.     if(flags & DRIVE)
  743.        printf("tdrive: %sn",drive);
  744.     if(flags & DIRECTORY)
  745.        printf("tdirectory: %sn",dir);
  746.     if(flags & FILENAME)
  747.        printf("tfile: %sn",file);
  748.     if(flags & EXTENSION)
  749.        printf("textension: %sn",ext);
  750.     return 0;
  751. }
  752.  
  753. 函数名: fprintf
  754. 功  能: 传送格式化输出到一个流中
  755. 用  法: int fprintf(FILE *stream, char *format[, argument,...]);
  756. 程序例:
  757. /* Program to create backup of the
  758.    AUTOEXEC.BAT file */
  759. #include <stdio.h>
  760. int main(void)
  761. {
  762.    FILE *in, *out;
  763.    if ((in = fopen("\AUTOEXEC.BAT", "rt"))
  764.        == NULL)
  765.    {
  766.       fprintf(stderr, "Cannot open input 
  767.        file.n");
  768.       return 1;
  769.    }
  770.    if ((out = fopen("\AUTOEXEC.BAK", "wt"))
  771.        == NULL)
  772.    {
  773.       fprintf(stderr, "Cannot open output 
  774.        file.n");
  775.       return 1;
  776.    }
  777.    while (!feof(in))
  778.       fputc(fgetc(in), out);
  779.    fclose(in);
  780.    fclose(out);
  781.    return 0;
  782. }
  783.  
  784.  
  785.  
  786. 函数名: FP_OFF
  787. 功  能: 获取远地址偏移量
  788. 用  法: unsigned FP_OFF(void far *farptr);
  789. 程序例:
  790. /* FP_OFF */
  791. #include <dos.h>
  792. #include <stdio.h>
  793. int main(void)
  794. {
  795.    char *str = "fpoff.c";
  796.    printf("The offset of this file in memory
  797.           is: %Fpn", FP_OFF(str));
  798.    return 0;
  799. }
  800.  
  801.  
  802. 函数名: FP_SEG
  803. 功  能: 获取远地址段值
  804. 用  法: unsigned FP_SEG(void far *farptr);
  805. 程序例:
  806. /* FP_SEG */
  807. #include <dos.h>
  808. #include <stdio.h>
  809. int main(void)
  810. {
  811.    char *filename = "fpseg.c";
  812.    printf("The offset of this file in memory
  813.    is: %Fpn", FP_SEG(filename));
  814.    return(0);
  815. }
  816.  
  817.  
  818.  
  819. 函数名: fputc
  820. 功  能: 送一个字符到一个流中
  821. 用  法: int fputc(int ch, FILE *stream);
  822. 程序例:
  823. #include <stdio.h>
  824. int main(void)
  825. {
  826.    char msg[] = "Hello world";
  827.    int i = 0;
  828.    while (msg[i])
  829.    {
  830.       fputc(msg[i], stdout);
  831.       i++;
  832.    }
  833.    return 0;
  834. }
  835.  
  836.  
  837.  
  838. 函数名: fputchar
  839. 功  能: 送一个字符到标准输出流(stdout)中
  840. 用  法: int fputchar(char ch);
  841. 程序例:
  842. #include <stdio.h>
  843. int main(void)
  844. {
  845.    char msg[] = "This is a test";
  846.    int i = 0;
  847.    while (msg[i])
  848.    {
  849.       fputchar(msg[i]);
  850.       i++;
  851.    }
  852.    return 0;
  853. }
  854.  
  855.  
  856.  
  857. 函数名: fputs
  858. 功  能: 送一个字符到一个流中
  859. 用  法: int fputs(char *string, FILE *stream);
  860. 程序例:
  861. #include <stdio.h>
  862. int main(void)
  863. {
  864.    /* write a string to standard output */
  865.    fputs("Hello worldn", stdout);
  866.    return 0;
  867. }
  868.  
  869.  
  870.  
  871. 函数名: fread
  872. 功  能: 从一个流中读数据
  873. 用  法: int fread(void *ptr, int size, int nitems, FILE *stream);
  874. 程序例:
  875. #include <string.h>
  876. #include <stdio.h>
  877. int main(void)
  878. {
  879.    FILE *stream;
  880.    char msg[] = "this is a test";
  881.    char buf[20];
  882.    if ((stream = fopen("DUMMY.FIL", "w+"))
  883.        == NULL)
  884.    {
  885.       fprintf(stderr,
  886.               "Cannot open output file.n");
  887.       return 1;
  888.    }
  889.    /* write some data to the file */
  890.    fwrite(msg, strlen(msg)+1, 1, stream);
  891.    /* seek to the beginning of the file */
  892.    fseek(stream, SEEK_SET, 0);
  893.    /* read the data and display it */
  894.    fread(buf, strlen(msg)+1, 1, stream);
  895.    printf("%sn", buf);
  896.    fclose(stream);
  897.    return 0;
  898. }
  899.  
  900.  
  901. 函数名: free
  902. 功  能: 释放已分配的块
  903. 用  法: void free(void *ptr);
  904. 程序例:
  905. #include <string.h>
  906. #include <stdio.h>
  907. #include <alloc.h>
  908. int main(void)
  909. {
  910.    char *str;
  911.    /* allocate memory for string */
  912.    str = malloc(10);
  913.    /* copy "Hello" to string */
  914.    strcpy(str, "Hello");
  915.    /* display string */
  916.    printf("String is %sn", str);
  917.    /* free memory */
  918.    free(str);
  919.    return 0;
  920. }
  921.  
  922. 函数名: freemem
  923. 功  能: 释放先前分配的DOS内存块
  924. 用  法: int freemem(unsigned seg);
  925. 程序例:
  926. #include <dos.h>
  927. #include <alloc.h>
  928. #include <stdio.h>
  929. int main(void)
  930. {
  931.    unsigned int size, segp;
  932.    int stat;
  933.    size = 64; /* (64 x 16) = 1024 bytes */
  934.    stat = allocmem(size, &segp);
  935.    if (stat < 0)
  936.       printf("Allocated memory at segment:
  937.       %xn", segp);
  938.    else
  939.       printf("Failed: maximum number of
  940.       paragraphs available is %un",
  941.       stat);
  942.    freemem(segp);
  943.    return 0;
  944. }
  945.  
  946.  
  947. 函数名: freopen
  948. 功  能: 替换一个流
  949. 用  法: FILE *freopen(char *filename, char *type, FILE *stream);
  950. 程序例:
  951. #include <stdio.h>
  952. int main(void)
  953. {
  954.    /* redirect standard output to a file */
  955.    if (freopen("OUTPUT.FIL", "w", stdout)
  956.        == NULL)
  957.       fprintf(stderr, "error redirecting
  958.               stdoutn");
  959.    /* this output will go to a file */
  960.    printf("This will go into a file.");
  961.    /* close the standard output stream */
  962.    fclose(stdout);
  963.    return 0;
  964. }
  965.  
  966.  
  967.  
  968. 函数名: frexp
  969. 功  能: 把一个双精度数分解为尾数的指数
  970. 用  法: double frexp(double value, int *eptr);
  971. 程序例:
  972. #include <math.h>
  973. #include <stdio.h>
  974. int main(void)
  975. {
  976.    double mantissa, number;
  977.    int exponent;
  978.    number = 8.0;
  979.    mantissa = frexp(number, &exponent);
  980.    printf("The number %lf is ", number);
  981.    printf("%lf times two to the ", mantissa);
  982.    printf("power of %dn", exponent);
  983.    return 0;
  984. }
  985.  
  986.  
  987. 函数名: fscanf
  988. 功  能: 从一个流中执行格式化输入
  989. 用  法: int fscanf(FILE *stream, char *format[,argument...]);
  990. 程序例:
  991. #include <stdlib.h>
  992. #include <stdio.h>
  993. int main(void)
  994. {
  995.    int i;
  996.    printf("Input an integer: ");
  997.    /* read an integer from the
  998.       standard input stream */
  999.    if (fscanf(stdin, "%d", &i))
  1000.       printf("The integer read was: %in",
  1001.              i);
  1002.    else
  1003.    {
  1004.       fprintf(stderr, "Error reading an 
  1005.               integer from stdin.n");
  1006.       exit(1);
  1007.    }
  1008.    return 0;
  1009. }
  1010.  
  1011.  
  1012.  
  1013. 函数名: fseek
  1014. 功  能: 重定位流上的文件指针
  1015. 用  法: int fseek(FILE *stream, long offset, int fromwhere);
  1016. 程序例:
  1017. #include <stdio.h>
  1018. long filesize(FILE *stream);
  1019. int main(void)
  1020. {
  1021.    FILE *stream;
  1022.    stream = fopen("MYFILE.TXT", "w+");
  1023.    fprintf(stream, "This is a test");
  1024.    printf("Filesize of MYFILE.TXT is %ld bytesn", filesize(stream));
  1025.    fclose(stream);
  1026.    return 0;
  1027. }
  1028. long filesize(FILE *stream)
  1029. {
  1030.    long curpos, length;
  1031.    curpos = ftell(stream);
  1032.    fseek(stream, 0L, SEEK_END);
  1033.    length = ftell(stream);
  1034.    fseek(stream, curpos, SEEK_SET);
  1035.    return length;
  1036. }
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042. 函数名: fsetpos
  1043. 功  能: 定位流上的文件指针
  1044. 用  法: int fsetpos(FILE *stream, const fpos_t *pos);
  1045. 程序例:
  1046. #include <stdlib.h>
  1047. #include <stdio.h>
  1048. void showpos(FILE *stream);
  1049. int main(void)
  1050. {
  1051.    FILE *stream;
  1052.    fpos_t filepos;
  1053.    /* open a file for update */
  1054.    stream = fopen("DUMMY.FIL", "w+");
  1055.    /* save the file pointer position */
  1056.    fgetpos(stream, &filepos);
  1057.    /* write some data to the file */
  1058.    fprintf(stream, "This is a test");
  1059.    /* show the current file position */
  1060.    showpos(stream);
  1061.    /* set a new file position, display it */
  1062.    if (fsetpos(stream, &filepos) == 0)
  1063.      showpos(stream);
  1064.    else
  1065.    {
  1066.       fprintf(stderr, "Error setting file 
  1067.        pointer.n");
  1068.       exit(1);
  1069.    }
  1070.    /* close the file */
  1071.    fclose(stream);
  1072.    return 0;
  1073. }
  1074. void showpos(FILE *stream)
  1075. {
  1076.    fpos_t pos;
  1077.    /* display the current file pointer
  1078.       position of a stream */
  1079.    fgetpos(stream, &pos);
  1080.    printf("File position: %ldn", pos);
  1081. }
  1082.  
  1083. 函数名: fstat
  1084. 功  能: 获取打开文件信息
  1085. 用  法: int fstat(char *handle, struct stat *buff);
  1086. 程序例:
  1087. #include <sysstat.h>
  1088. #include <stdio.h>
  1089. #include <time.h>
  1090. int main(void)
  1091. {
  1092.    struct stat statbuf;
  1093.    FILE *stream;
  1094.    /* open a file for update */
  1095.    if ((stream = fopen("DUMMY.FIL", "w+"))
  1096.        == NULL)
  1097.    {
  1098.       fprintf(stderr, "Cannot open output 
  1099.               file.n");
  1100.       return(1);
  1101.    }
  1102.    fprintf(stream, "This is a test");
  1103.    fflush(stream);
  1104.    /* get information about the file */
  1105.    fstat(fileno(stream), &statbuf);
  1106.    fclose(stream);
  1107.    /* display the information returned */
  1108.    if (statbuf.st_mode & S_IFCHR)
  1109.       printf("Handle refers to a device.n");
  1110.    if (statbuf.st_mode & S_IFREG)
  1111.       printf("Handle refers to an ordinary 
  1112.              file.n");
  1113.    if (statbuf.st_mode & S_IREAD)
  1114.       printf("User has read permission on 
  1115.              file.n");
  1116.    if (statbuf.st_mode & S_IWRITE)
  1117.       printf("User has write permission on 
  1118.               file.n");
  1119.    printf("Drive letter of file: %cn",
  1120.    'A'+statbuf.st_dev);
  1121.    printf("Size of file in bytes: %ldn",
  1122.    statbuf.st_size);
  1123.    printf("Time file last opened: %sn",
  1124.    ctime(&statbuf.st_ctime));
  1125.    return 0;
  1126. }
  1127.  
  1128.  
  1129.  
  1130. 函数名: ftell
  1131. 功  能: 返回当前文件指针
  1132. 用  法: long ftell(FILE *stream);
  1133. 程序例:
  1134. #include <stdio.h>
  1135. int main(void)
  1136. {
  1137.    FILE *stream;
  1138.    stream = fopen("MYFILE.TXT", "w+");
  1139.    fprintf(stream, "This is a test");
  1140.    printf("The file pointer is at byte 
  1141.           %ldn", ftell(stream));
  1142.    fclose(stream);
  1143.    return 0;
  1144. }
  1145.  
  1146.  
  1147.  
  1148. 函数名: fwrite
  1149. 功  能: 写内容到流中
  1150. 用  法: int fwrite(void *ptr, int size, int nitems, FILE *stream);
  1151. 程序例:
  1152. #include <stdio.h>
  1153. struct mystruct
  1154. {
  1155.   int i;
  1156.   char ch;
  1157. };
  1158. int main(void)
  1159. {
  1160.    FILE *stream;
  1161.    struct mystruct s;
  1162.    if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */
  1163.    {
  1164.       fprintf(stderr, "Cannot open output file.n");
  1165.       return 1;
  1166.    }
  1167.    s.i = 0;
  1168.    s.ch = 'A';
  1169.    fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */
  1170.    fclose(stream); /* close file */
  1171.    return 0;
  1172. }