home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / 64 < prev    next >
Encoding:
Text File  |  1992-04-14  |  20.0 KB  |  871 lines

  1. /*    Copyright (C) 1990-1992 MetaWare Incorporated; All Rights Reserved  */
  2.  
  3. /**** name=fabs ****/
  4. #define main TEST_fabs
  5.  
  6. #include <stdio.h>
  7. #include <math.h>
  8.  
  9. void main() {
  10.    double absolut, real = -32.234763;
  11.  
  12.    absolut = fabs(real);
  13.    printf("The absolute value of %f is: %f\n",
  14.           real, absolut);
  15.    }
  16. /* End fabs  */
  17. #undef main
  18. /**** name=fclose ****/
  19. #define main TEST_fclose
  20.  
  21. /*
  22.    The program fragment below attempts to open test.dat for  reading.    It
  23.    later attempts to close test.dat prior to opening fclose.tmp for writing
  24.    (using the same FILE variable).  For this example to work, you must have
  25.    a file named test.dat in your current directory.
  26. */
  27.  
  28. #include <stdio.h>
  29. #define  FAILURE (-1)
  30.  
  31. int main() {
  32.    FILE *FP;
  33.  
  34.    if ((FP = fopen("test.dat", "r")) == NULL) {
  35.       perror("fopen of test.dat");
  36.       return FAILURE;
  37.       }
  38.    if (fclose(FP) != 0)
  39.       perror("fclose of test.dat");
  40.    if ((FP = fopen("fclose.tmp", "w")) == NULL) {
  41.       perror("fopen of fclose.tmp");
  42.       return FAILURE;
  43.       }
  44.    puts("fopen and fclose were successful.");
  45.    }
  46. /* End fclose  */
  47. #undef main
  48. #undef   FAILURE
  49. /**** name=_fdopen ****/
  50. #define main TEST__fdopen
  51.  
  52. #include <fcntl.h>
  53. #include <io.h>
  54. #include <share.h>
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57.  
  58. void main(void) {
  59.    FILE *fp;
  60.    int pan;
  61.    int c;
  62.  
  63.    pan = _sopen("test.dat",
  64.                 O_RDONLY | O_TEXT,
  65.                 _SH_DENYWR
  66.                 );
  67.    if (pan != -1)
  68.       printf("File test.dat exists, handle=%d\n", pan);
  69.    else
  70.       printf("File test.dat cannot be sopened,"
  71.              " error code=%d\n",pan);
  72.    if((fp = _fdopen(pan, "r")) == NULL) {
  73.       perror("Error opening test.dat");
  74.       return;
  75.       }
  76.    /* Get and print characters until the end of file. */
  77.    while((c = fgetc(fp)) != EOF)
  78.       printf("%c", c);
  79.  
  80.    /* Close the file.  Now any other process can read and write to the file
  81.       test.dat until some other process puts a lock on it. */
  82.    fclose(fp);
  83.    }
  84. /* End _fdopen  */
  85. #undef main
  86. /**** name=fgetc ****/
  87. #define main TEST_fgetc
  88.  
  89. /*
  90.    This program prints out test.dat character by character using fgetc.
  91. */
  92. #include <stdio.h>
  93.  
  94. void main() {
  95.    FILE *FP;
  96.    signed char c;
  97.  
  98.    if ((FP = fopen("test.dat", "r")) == NULL)
  99.       perror("fopen of test.dat");
  100.    while (!feof(FP)) {
  101.       c = fgetc(FP);
  102.       fputc(c, stdout);
  103.       }
  104.    }
  105. /* End fgetc  */
  106. #undef main
  107. /**** name=_fgetchar ****/
  108. #define main TEST__fgetchar
  109.  
  110. /*
  111.    This  program  copies  standard   input   character   by   character  to
  112.    fgetchar.tmp and to standard  output.    Similar  examples are given for
  113.    fgetc and getc, pointing out the differences among the functions.
  114. */
  115.    #include <stdio.h>
  116.  
  117.    void main() {
  118.       FILE *FP1;
  119.  
  120.       if ((FP1 = fopen("fgetchar.tmp", "w")) == NULL)
  121.          perror("Cannot open fgetchar.tmp.");
  122.       printf("Please enter text, ending"
  123.              " with the ENTER key.\n\n");
  124.       while ('\n' != fputc(fputchar(fgetchar()), FP1));
  125.    }
  126. /* End _fgetchar  */
  127. #undef main
  128. /**** name=fgetpos ****/
  129. #define main TEST_fgetpos
  130.  
  131.  
  132. #include <stdio.h>
  133.  
  134. void print_it(FILE *FP) {
  135.    int c;
  136.    fpos_t pos1,pos2;
  137.    for (;;) {
  138.       fgetpos(FP, &pos1);
  139.       do {   /* skip first line */
  140.          c = fgetc(FP);
  141.          if (c == EOF) return;
  142.          } while (c != '\n');
  143.       do {   /* print second line */
  144.          c = fgetc(FP);
  145.          if (c == EOF) return;
  146.          printf("%c", c);
  147.          } while (c != '\n');
  148.  
  149.       fgetpos(FP, &pos2);
  150.       fsetpos(FP, &pos1);  /* reposition to first line */
  151.  
  152.       do {   /* print first line */
  153.          c = fgetc(FP);
  154.          if (c == EOF) return;
  155.          printf("%c", c);
  156.          } while (c != '\n');
  157.       fsetpos(FP, &pos2);
  158.       }
  159.    }
  160.  
  161. void main() {
  162.    FILE *FP;
  163.  
  164.    if (((FP = fopen("test.dat","r")) == NULL))
  165.       return;
  166.    print_it(FP);
  167.    fclose(FP);
  168.   }
  169. /* End fgetpos  */
  170. #undef main
  171. /**** name=fgets ****/
  172. #define main TEST_fgets
  173.  
  174. /*
  175.    The  program  below  prints  test.dat   line  by  line.    This  example
  176.    illustrates the use of fgets, and fopen.
  177. */
  178.  
  179. #include <stdio.h>
  180. #include <stdlib.h>
  181. #define  LINESIZE (80)
  182. void main() {
  183.    FILE *FP;
  184.    char line[LINESIZE];
  185.    if ((FP = fopen("test.dat", "r")) == NULL) {
  186.       perror("cannot open test.dat");
  187.       return;
  188.       }
  189.    while (fgets(line, LINESIZE, FP)) {
  190.       /* fgets returns NULL (FALSE) when it                              */
  191.       /* cannot get any more characters.                                 */
  192.       fputs(line, stdout);
  193.       }
  194.    }
  195. /* End fgets  */
  196. #undef main
  197. #undef   LINESIZE
  198. /**** name=__FILE__ ****/
  199. #define main TEST___FILE__
  200. /* End __FILE__  */
  201. #undef main
  202. /**** name=_filelength ****/
  203. #define main TEST__filelength
  204.  
  205. /*
  206.    This program determines the length of a file.
  207. */
  208.  
  209. #include <stdio.h>
  210. #include <io.h>
  211.  
  212. FILE *stream;
  213. long length;
  214.  
  215. void main() {
  216.    /* Must open file first. */
  217.    stream = fopen("test.dat", "r");
  218.    length = _filelength (fileno(stream));
  219.    if (length == -1L)
  220.       puts("Could not find file test.dat.");
  221.    else
  222.       printf("test.dat is %ld bytes long.\n", length);
  223.    }
  224.  
  225. /* End _filelength  */
  226. #undef main
  227. /**** name=_fileno ****/
  228. #define main TEST__fileno
  229.  
  230. /*
  231.    Program to obtain the predefined file handles.
  232. */
  233. #include <stdio.h>
  234.  
  235. void TEST__fileno() {
  236.  
  237.    puts("Predefined file handles:");
  238.    puts("\nDevice           handle");
  239.    printf("Standard input     %d\n", _fileno(stdin));
  240.    printf("Standard output    %d\n", _fileno(stdout));
  241.    printf("Standard error     %d\n", _fileno(stderr));
  242.    }
  243. /* End _fileno  */
  244. #undef main
  245. /**** name=_fmalloc ****/
  246. #define main TEST__fmalloc
  247.  
  248.  
  249. #include <stdio.h>
  250. #include <malloc.h>
  251. #include <dos.h>
  252.  
  253. void main() {
  254.    _Far char *new_array;
  255.  
  256.    new_array = _fmalloc(15000 * sizeof(long));
  257.  
  258.    if (new_array == NULL) {
  259.       printf("_fmalloc: Not enough memory"
  260.              " for 15,000 longs\n");
  261.       new_array = _fmalloc(5000 * sizeof(long));
  262.       if (new_array == NULL)
  263.          printf("_fmalloc: Not enough memory"
  264.                 " for 5,000 longs\n");
  265.       else
  266.          printf("_fmalloc: Allocated 5,000 longs"
  267.                 " at %x:%lx\n",
  268.                 _FP_SEG(new_array),
  269.                 _FP_OFF(new_array));
  270.       }
  271.    else
  272.       printf("_fmalloc: Allocated 15,000 longs"
  273.              " at %x:%lx\n",
  274.  
  275.              _FP_SEG(new_array),
  276.              _FP_OFF(new_array));
  277.    }
  278. /* End _fmalloc  */
  279. #undef main
  280. /**** name=fopen ****/
  281. #define main TEST_fopen
  282. /* End fopen  */
  283. #undef main
  284. /**** name=_FP_X ****/
  285. #define main TEST__FP_X
  286.  
  287. /*
  288.    This program displays the segment and offset of a far pointer.
  289. */
  290. #include <dos.h>
  291. #include <stdio.h>
  292.  
  293. void main() {
  294.    struct ovly {
  295.       int offs;
  296.       short segs;
  297.       };
  298.    union {
  299.       _Far char *a;
  300.       struct ovly q;
  301.       } x;
  302.    unsigned int seg, off;
  303.  
  304.    x.q.offs = 320;     /* Line two, column one. */
  305.    x.q.segs = 0x1C;    /* Phar Lap screen segment. */
  306.    puts("\nchar *a is stored at: ");
  307.  
  308.    seg = _FP_SEG(x.a);
  309.    off = _FP_OFF(x.a);
  310.    printf("Segment: 0x%.4x\n"
  311.           "Offset : 0x%.4x\n", seg, off);
  312.    }
  313. /* End _FP_*  */
  314. #undef main
  315. /**** name=fprintf ****/
  316. #define main TEST_fprintf
  317.  
  318. /*
  319.    Results are written to file fprintf.tmp.
  320. */
  321. #include <stdio.h>
  322. #define  FAILURE  (-1)
  323.  
  324. int main() {
  325.    FILE   *FP;
  326.    char    s[14] = "like this one", c = '*';
  327.    int     i = 10, x = 255, o = 45;
  328.    double  d = 3.1415927, nf = -3.449123;
  329.  
  330.    if ((FP = fopen("fprintf.tmp", "w")) == NULL) {
  331.       perror("Cannot open fprintf.tmp.");
  332.       return FAILURE;
  333.       }
  334.    puts("Results are in fprintf.tmp.");
  335.    fprintf(FP,"fprintf prints strings (%s),\n", s);
  336.    fprintf(FP,"decimal numbers(%d),", i);
  337.    fprintf(FP," hex numbers(%04X),\n", x);
  338.    fprintf(FP,"floating-point numbers (%+.4e)\n", d);
  339.    fprintf(FP,"percent signs(%%),\n");
  340.    fprintf(FP,"characters (%-5c),\n", c);
  341.    fprintf(FP,"negative floating-points"
  342.            " (% 010.2e)\n", nf);
  343.    fprintf(FP,"and even octal numbers (%-+#5o).", o);
  344.    fclose(FP);
  345.    }
  346. /* End fprintf  */
  347. #undef main
  348. #undef   FAILURE
  349. /**** name=fputc ****/
  350. #define main TEST_fputc
  351. /* End fputc  */
  352. #undef main
  353. /**** name=_fputchar ****/
  354. #define main TEST__fputchar
  355. /* End _fputchar  */
  356. #undef main
  357. /**** name=fputs ****/
  358. #define main TEST_fputs
  359. /* End fputs  */
  360. #undef main
  361. /**** name=fread ****/
  362. #define main TEST_fread
  363.  
  364. /*
  365.    The  program below copies test.dat, a block at  a  time,  to  fread.tmp.
  366.    This example illustrates the use of fread and fwrite.
  367. */
  368. #include <stdio.h>
  369. #define  FAILURE   (-1)
  370. #define  BLOCKSIZE (128)
  371. #define  MAXBUF (256)
  372.  
  373. int main() {
  374.    char  buf[MAXBUF];
  375.    FILE *FP1, *FP2;
  376.    size_t i,j;
  377.  
  378.    puts("Testing fread...\n");
  379.    if ((FP1 = fopen("test.dat", "r")) == NULL) {
  380.       perror("Cannot open test.dat");
  381.       return FAILURE;
  382.       }
  383.    if ((FP2 = fopen("fread.tmp", "w")) == NULL) {
  384.       perror("Cannot open fread.tmp.");
  385.       return FAILURE;
  386.       }
  387.    i = fread(buf, sizeof(char), BLOCKSIZE, FP1); 
  388.    j = fwrite(buf, sizeof(char), i, FP2);
  389.  
  390.    printf("i = %d, and j = %d.\n",i,j);
  391.    if (fclose(FP1) == 0)
  392.       puts("File test.dat is now closed.");
  393.    else puts("Unable to close file test.dat.");
  394.    if (fclose(FP2) == 0)
  395.       puts("File fread.tmp is now closed.");
  396.    else puts("Unable to close file fread.tmp.");
  397.    }
  398. /* End fread  */
  399. #undef main
  400. #undef   FAILURE
  401. #undef   BLOCKSIZE
  402. #undef   MAXBUF
  403. /**** name=freopen ****/
  404. #define main TEST_freopen
  405.  
  406. #include <stdio.h>
  407.  
  408. void main() {
  409.    printf("Testing freopen."
  410.           "  Output is in freopen.tmp\n");
  411.    freopen("freopen.tmp", "w", stdout);
  412.    printf("This will not appear on the screen.\n");
  413.    printf("It will appear in the file freopen.tmp.\n");
  414.    freopen("con", "w", stdout);
  415.    printf("freopen test is finished.");
  416.    }
  417. /* End freopen  */
  418. #undef main
  419. /**** name=frexp ****/
  420. #define main TEST_frexp
  421.  
  422. #include <stdio.h>
  423. #include <math.h>
  424.  
  425. void main() {
  426.    int exp;
  427.    double x, num=73.0;
  428.  
  429.    puts("Testing frexp...\n");
  430.    x = frexp(num, &exp);
  431.    printf("For the number %e.\n",num); 
  432.    printf("Fractional part = %e,\n"
  433.           "Exponent part   = %d.\n", x, exp);
  434.    }
  435.  
  436. /* End frexp  */
  437. #undef main
  438. /**** name=fscanf ****/
  439. #define main TEST_fscanf
  440.  
  441. #include <stdio.h>
  442.  
  443. void main() {
  444.    FILE *FP;
  445.    char  s1[11], s2[19] = "but missed eleven.";
  446.    char  s3[19] = "but missed eleven.";
  447.    int   i, j;
  448.  
  449.    puts("Testing fscanf...\n");
  450.    if ((FP = fopen("fscanf.dat", "r")) == NULL) {
  451.       perror("Cannot open fscanf.dat.");
  452.       return;
  453.       }
  454.    fscanf(FP,"%11c%d %%%d %[^z]z", s1, &i, &j, s2);
  455.    printf("%11s%d, %s%s\n", s1, i,
  456.           j == 11 ? "11, " : "",s2);
  457.    fgets(s1,11,FP);
  458.    fscanf(FP,"%11c%d %%%d %[^z]z", s1, &i, &j, s3);
  459.    printf("%11s%d, %s%s\n", s1, i,
  460.           j == 11 ? "11, " : "",s3);
  461.    }
  462. /* End fscanf  */
  463. #undef main
  464. /**** name=fseek ****/
  465. #define main TEST_fseek
  466.  
  467. /*
  468.    This program prints the last ten bytes of test.dat
  469. */
  470.  
  471. #include <stdio.h>
  472. #define  FAILURE (-1)
  473.  
  474. int main() {
  475.    FILE *FP;
  476.    char c;
  477.  
  478.    if (((FP = fopen("test.dat","r")) == NULL))
  479.       return FAILURE;
  480.  
  481.    fseek(FP, -18L, SEEK_END);
  482.    printf("Now at position %ld in file test.dat.\n",
  483.           ftell(FP));
  484.    while (!feof(FP)) {
  485.       c = fgetc(FP);
  486.       printf("%c", c);
  487.       }
  488.    }
  489. /* End fseek  */
  490. #undef main
  491. #undef   FAILURE
  492. /**** name=fsetpos ****/
  493. #define main TEST_fsetpos
  494. /* End fsetpos  */
  495. #undef main
  496. /**** name=_fsopen ****/
  497. #define main TEST__fsopen
  498.  
  499. #include <share.h>
  500. #include <stdio.h>
  501. #include <stdlib.h>
  502.  
  503. void main(void) {
  504.    FILE *fp;
  505.    char c;
  506.  
  507.    /*
  508.       The next line opens the file test.dat for reading.  If another
  509.       process tries to access test.dat after this program has opened it,
  510.       the other process will be able to read from the file, but not write
  511.       to it.
  512.    */
  513.    if((fp = _fsopen("test.dat", "r", _SH_DENYWR))
  514.                                                                  == NULL) {
  515.  
  516.       perror("Error opening test.dat");
  517.       return;
  518.       }
  519.  
  520.    while(!feof(fp)) {   /* While it's not the end */
  521.       c = fgetc(fp);    /*  get another character */
  522.       printf("%c", c);  /*  and print it out.     */
  523.       }
  524.  
  525.    /* Close the file. */
  526.    fclose(fp);
  527.    /*
  528.       Now any other process can read and write to the file test.dat until
  529.       some other process puts a lock on it.
  530.    */
  531.    }
  532. /* End _fsopen  */
  533. #undef main
  534. /**** name=ftell ****/
  535. #define main TEST_ftell
  536. /* End ftell  */
  537. #undef main
  538. /**** name=_ftime ****/
  539. #define main TEST__ftime
  540.  
  541. #include <types.h>
  542. #include <timeb.h>
  543. #include <time.h>
  544. #undef   timezone
  545. #include <stdio.h>
  546. #include <stdlib.h>
  547.  
  548. void main() {
  549.    struct _timeb x;
  550.  
  551.    puts("Testing _ftime...\n");
  552.    _ftime(&x);
  553.    printf("daylight is:%d\n"
  554.           "timezone is:%d\n"
  555.           "time is:%ld\n",
  556.           x.dstflag,x.timezone,x.time);
  557.    printf("time is:%ld\n",time(NULL));
  558.    tzset();
  559.    _ftime(&x);
  560.    printf("daylight is:%d\n"
  561.           "timezone is:%d\n"
  562.           "time is:%ld\n",
  563.           x.dstflag,x.timezone,x.time);
  564.    printf("time is:%ld\n",time(NULL));
  565.    }
  566. /* End _ftime  */
  567. #undef main
  568. /**** name=fwrite ****/
  569. #define main TEST_fwrite
  570. /* End fwrite  */
  571. #undef main
  572. /**** name=getc ****/
  573. #define main TEST_getc
  574.  
  575. /*
  576.    This program uses getc to print out test.dat.
  577. */
  578. #include <stdio.h>
  579.  
  580. void main() {
  581.    FILE *FP;
  582.    int c;
  583.    if ((FP = fopen("test.dat", "r")) == NULL)
  584.       perror("fopen of test.dat");
  585.    while (!feof(FP)) {
  586.       c = getc(FP);
  587.       printf("%c", c);
  588.       }
  589.    }
  590. /* End getc  */
  591. #undef main
  592. /**** name=_getchX ****/
  593. #define main TEST__getchX
  594.  
  595. #include <conio.h>
  596. #include <stdio.h>
  597.  
  598. void main() {
  599.    int c;
  600.  
  601.    puts("Every other character you key"
  602.         " will be displayed.");
  603.    do {
  604.       c = _getche();
  605.       if (c != '\r')
  606.           c = _getch();
  607.       } while (c != '\r');
  608.    }
  609.  
  610. /* End _getch*  */
  611. #undef main
  612. /**** name=getchar ****/
  613. #define main TEST_getchar
  614.  
  615.  
  616. /*
  617.    This program copies standard input character by character to getchar.tmp
  618.    and to standard output.  Similar examples are given for fgetc  and getc,
  619.    pointing out the differences among the functions.
  620. */
  621. #include <stdio.h>
  622. #undef   getchar /* Undefine macros and access                           */
  623. #undef   putchar /*  the named functions.                                */
  624. void main() {
  625.    FILE *FP1;
  626.  
  627.    printf("Enter characters; end with"
  628.           " the ENTER key.\n");
  629.    if ((FP1 = fopen("getchar.tmp", "w")) == NULL)
  630.       perror("Cannot open getchar.tmp.");
  631.    while ('\n' != fputc(putchar(getchar()), FP1));
  632.    }
  633. /* End getchar  */
  634. #undef main
  635. /**** name=_getcwd ****/
  636. #define main TEST__getcwd
  637.  
  638. /*
  639.    This program gets the current working directory.
  640. */
  641.  
  642. #include <stdio.h>
  643. #include <direct.h>
  644.  
  645. void main() {
  646.    char *cwd = NULL;
  647.    int  maxlen = 66;
  648.  
  649.    if ((cwd = _getcwd(cwd, maxlen)) != NULL)
  650.       printf("Current working directory: %s\n", cwd);
  651.    else
  652.       perror("Error in _getcwd.");
  653.    }
  654.  
  655. /* End _getcwd  */
  656. #undef main
  657. /**** name=getenv ****/
  658. #define main TEST_getenv
  659.  
  660. /*
  661.    This program displays the value of the PATH environment variable.
  662. */
  663. #include <stdio.h>
  664. #include <stdlib.h>
  665. void main() {
  666.    char *ev;
  667.    if ((ev = getenv("PATH")) != NULL)
  668.       printf("The value of PATH is:\n%s", ev);
  669.    else puts("The PATH variable is not set.\n");
  670.    }
  671.  
  672. /* End getenv  */
  673. #undef main
  674. /**** name=_getpid ****/
  675. #define main TEST__getpid
  676.  
  677. /*
  678.    This program displays the caller's process ID.
  679. */
  680.  
  681. #include <process.h>
  682. #include <stdio.h>
  683.  
  684. void main() {
  685.    printf("The process ID is: %d\n", _getpid());
  686.    }
  687.  
  688. /* End _getpid  */
  689. #undef main
  690. /**** name=_getpvect ****/
  691. #define main TEST__getpvect
  692. /* End _getpvect  */
  693. #undef main
  694. /**** name=_getrvect ****/
  695. #define main TEST__getrvect
  696. /* End _getrvect  */
  697. #undef main
  698. /**** name=gets ****/
  699. #define main TEST_gets
  700.  
  701. /*
  702.    The program below copies a line from standard input to  standard output.
  703.    It illustrates the use of gets and puts.
  704. */
  705.  
  706. #include <stdio.h>
  707. #define  LINESIZE (256)
  708.  
  709. void main() {
  710.    char line[LINESIZE];
  711.  
  712.    printf("\nWaiting for keyboard input: ");
  713.    if (gets(line))
  714.       puts(line);
  715.    }
  716.  
  717. /* End gets  */
  718. #undef main
  719. #undef   LINESIZE
  720. /**** name=gmtime ****/
  721. #define main TEST_gmtime
  722.  
  723. /*
  724.    This  example  illustrates   the   use  of  asctime()  with  time()  and
  725.    localtime().
  726. */
  727. #include <time.h>
  728. #include <stdio.h>
  729.  
  730. void main() {
  731.    time_t t;
  732.    struct tm tim_hd;
  733.    char *str;
  734.  
  735.    time(&t);
  736.    tim_hd = *gmtime(&t);
  737.    str = asctime(&tim_hd);
  738.    printf("Greenwich Mean Time: %s", str);
  739.    }
  740. /* End gmtime  */
  741. #undef main
  742. /**** name=HUGE_VAL ****/
  743. #define main TEST_HUGE_VAL
  744.  
  745. #include <math.h>
  746. #include <stdio.h>
  747. #include <stdlib.h>
  748.  
  749. void main() {
  750.    double x = 1.0;
  751.    int counter;
  752.    for (counter = 1; counter < 10000; (counter += 20)) {
  753.       if (exp(x) >= HUGE_VAL) {
  754.          printf("\n%d\t.....Number too big."
  755.                 "  Bye.", counter);
  756.          break;
  757.          }
  758.       else printf("\n%d\t%g", counter, exp(x));
  759.       x += counter;
  760.       }
  761.    }
  762. /* End HUGE_VAL  */
  763. #undef main
  764. /**** name=_hypot ****/
  765. #define main TEST__hypot
  766.  
  767. #include <math.h>
  768. #include <stdio.h>
  769.  
  770. void main() {
  771.    double base=3.0, height=4.0;
  772.  
  773.    puts("Testing _hypot...\n");
  774.    printf("Base = %.2f, Height = %.2f,"
  775.           " Hypotenuse = %.2f\n",
  776.           base,height,_hypot(base,height));
  777.    base = 1.0, height = 1.0;
  778.    printf("Base = %.2f, Height = %.2f,"
  779.           " Hypotenuse = %.2f\n",
  780.           base,height,_hypot(base,height));
  781.    base = 8.0, height = -6.0;
  782.    printf("Base = %.2f, Height = %.2f,"
  783.           " Hypotenuse = %.2f\n",
  784.           base, height, _hypot(base, height));
  785.    }
  786.  
  787. /* End _hypot  */
  788. #undef main
  789.  
  790. /*****names*****/
  791.  
  792. char * names[]={
  793.    "fabs",
  794.    "fclose",
  795.    "_fdopen",
  796.    "fgetc",
  797.    "_fgetchar",
  798.    "fgetpos",
  799.    "fgets",
  800.    "_filelength",
  801.    "_fileno",
  802.    "_fmalloc",
  803.    "_FP_X",
  804.    "fprintf",
  805.    "fread",
  806.    "freopen",
  807.    "frexp",
  808.    "fscanf",
  809.    "fseek",
  810.    "_fsopen",
  811.    "_ftime",
  812.    "getc",
  813.    "_getchX",
  814.    "getchar",
  815.    "_getcwd",
  816.    "getenv",
  817.    "_getpid",
  818.    "gets",
  819.    "gmtime",
  820.    "HUGE_VAL",
  821.    "_hypot",
  822.    "",""};
  823.    int nextfunum;
  824. void main() {
  825.    char ans[90];
  826.    for (;;) {
  827.       for (int j=0;j< 29;j++)
  828.       if (j%3==2) printf("%4d %-21s\n",j+1,names[j]);
  829.       else printf("%4d %-21s",j+1,names[j]);
  830.       printf("\n\nPlease enter a number from the above list (enter=%d, exit=0): ",++nextfunum);
  831.       gets(ans);
  832.       if (ans[0] != 0) nextfunum=atoi(ans);
  833.       printf("\n\n\n");
  834.       switch(nextfunum) {
  835.          case 0:exit(0);
  836.          case 1:TEST_fabs();break;
  837.          case 2:TEST_fclose();break;
  838.          case 3:TEST__fdopen();break;
  839.          case 4:TEST_fgetc();break;
  840.          case 5:TEST__fgetchar();break;
  841.          case 6:TEST_fgetpos();break;
  842.          case 7:TEST_fgets();break;
  843.          case 8:TEST__filelength();break;
  844.          case 9:TEST__fileno();break;
  845.          case 10:TEST__fmalloc();break;
  846.          case 11:TEST__FP_X();break;
  847.          case 12:TEST_fprintf();break;
  848.          case 13:TEST_fread();break;
  849.          case 14:TEST_freopen();break;
  850.          case 15:TEST_frexp();break;
  851.          case 16:TEST_fscanf();break;
  852.          case 17:TEST_fseek();break;
  853.          case 18:TEST__fsopen();break;
  854.          case 19:TEST__ftime();break;
  855.          case 20:TEST_getc();break;
  856.          case 21:TEST__getchX();break;
  857.          case 22:TEST_getchar();break;
  858.          case 23:TEST__getcwd();break;
  859.          case 24:TEST_getenv();break;
  860.          case 25:TEST__getpid();break;
  861.          case 26:TEST_gets();break;
  862.          case 27:TEST_gmtime();break;
  863.          case 28:TEST_HUGE_VAL();break;
  864.          case 29:TEST__hypot();break;
  865.          default:printf("I don't recognize that answer\n");nextfunum=-1;break;
  866.          }
  867.       printf("\n\npress enter to select another function\n");
  868.       gets(ans);
  869.       }
  870.    }
  871.