home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e060 / 2.ddi / FANDC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-03  |  2.3 KB  |  95 lines

  1. #include    <stdio.h>
  2. #include    "clink.h"
  3.  
  4. /********
  5.  *
  6.  * Add temperature conversion functions to the basic compliment
  7.  * of KMAN functions.
  8.  *
  9.  ********/
  10. centry(argc, argv)
  11. int argc;
  12. struct    item    argv[];
  13. {
  14.     /* check for the Farenheit TO Celsius conversion function    */
  15.     if (strcmp(argv[0].data.str, "FTOC") == 0)
  16.         ftoc(argc, argv);
  17.  
  18.     /* check for the Celsius TO Farenheit conversion function    */
  19.     else if (strcmp(argv[0].data.str, "CTOF") == 0)
  20.         ctof(argc, argv);
  21.  
  22.     else    /* unrecognized function name ... return ERROR !!!   */
  23.         return (-1);
  24.  
  25.     return (0);    /* return the sucessful response         */
  26. }
  27.  
  28. /********
  29.  *
  30.  * ftoc - convert from the farenheit temperature scale into the celcius
  31.  *      temperature scale.
  32.  *
  33.  ********/
  34. ftoc(argc, argv)
  35. int    argc;            /* input argument count             */
  36. struct    item    argv[];        /* input argument data vector         */
  37. {
  38.     double    c;        /* scratch for celsius temp value    */
  39.  
  40.     c = 0.0;
  41.     if (argc != 2)
  42.         /* ERROR !!!  incorrect number of arguments         */
  43.         ;
  44.     else {
  45.         /* process integer arguments ...             */
  46.         if (argv[1].type == DINT)
  47.             c = (argv[1].data.intt - 32) * 5.0 / 9.0;
  48.  
  49.         /* process floating point numeric arguments ...         */
  50.         else if (argv[1].type == DNUM)
  51.             c = (argv[1].data.num  - 32.0) * 5.0 / 9.0;
  52.  
  53.         else    /* ERROR !!!  incorrect data type         */
  54.             ;
  55.     }
  56.  
  57.     /* assign the results into the first input 'item' structure  */
  58.     argv[0].data.num = c;
  59.     argv[0].type = DNUM;
  60. }
  61.  
  62. /********
  63.  *
  64.  * ctof - convert from the celsius temperature scale into the farenheit
  65.  *      temperature scale.
  66.  *
  67.  ********/
  68. ctof(argc, argv)
  69. int    argc;            /* input argument count             */
  70. struct    item    argv[];        /* input argument data vector         */
  71. {
  72.     double    f;        /* scratch for farenheit temp value  */
  73.  
  74.     f = 0.0;
  75.     if (argc != 2)
  76.         /* ERROR !!!  incorrect number of arguments         */
  77.         ;
  78.     else {
  79.         /* process integer arguments ...             */
  80.         if (argv[1].type == DINT)
  81.             f = (argv[1].data.intt * 9.0 / 5.0) + 32.0;
  82.  
  83.         /* process floating point numeric arguments ...         */
  84.         else if (argv[1].type == DNUM)
  85.             f = (argv[1].data.num  * 9.0 / 5.0) + 32.0;
  86.  
  87.         else    /* ERROR !!!  incorrect data type         */
  88.             ;
  89.     }
  90.  
  91.     /* assign the results into the first input 'item' structure  */
  92.     argv[0].data.num = f;
  93.     argv[0].type = DNUM;
  94. }
  95.