home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 162_01 / demo2.c < prev    next >
Text File  |  1985-08-21  |  1KB  |  51 lines

  1. /*    file    demo2.c    */
  2. /*    Returns inverse sine, in radians and degrees,
  3.     or and error message if out of range.    */
  4. /*    Use CTRL-C to exit from demo.    */
  5. #include    fprintf.h
  6. #define    EOF -1
  7. #define    MAXL    40
  8. extern    float    asin(),fdpi(),atof();
  9. extern    char    *ftoa();
  10. float    rtod();
  11. extern    int    b34arg;
  12. extern    int    portc,portd;
  13.  
  14. main() {
  15.     static    float    fnuma,fnumb,fnumc;
  16.     static    int    len;
  17.     static    char    line[MAXL];
  18.     portd = 188; portc = 189;    /* must be YOUR hardware ports */
  19.     while(len = getline(line,MAXL) < MAXL) {
  20.         fnuma = atof(line);
  21.         fnumb = asin(fnuma);
  22.         xpand1();    /* automatically external ? */
  23.         if(b34arg == 1)
  24.          printf("\n%g is out of range for inverse sine operation\n",fnuma);
  25.         else {
  26.             printf("\nInverse sine of %g is %f radians, ",fnuma,fnumb);
  27.             fnumc = rtod(fnumb);
  28.             printf("or %f degrees.\n",fnumc);
  29.         }
  30.     }
  31. }
  32.  
  33. getline(s,lim)    /* get line into s, return length */
  34. char    s[];
  35. int    lim;
  36. {
  37.     int    c,i;
  38.     i = 0;
  39.     while(--lim > 0 && (c=getchar()) != EOF && c != '\n')
  40.         s[i++] = c;
  41.     if (c == '\n')
  42.         s[i++] = c;
  43.     s[i] ='\0';
  44.     return(i);
  45. }
  46. float    rtod(fn)    /*    convert Radians TO Degrees    */
  47. float    fn;
  48. {
  49.     return(fdpi(fn) * 180);
  50. }
  51.