home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 162_01 / demo1.c < prev    next >
Encoding:
Text File  |  1985-08-21  |  1.0 KB  |  42 lines

  1. /*     file    demo1.c */
  2. #include fprintf.h
  3. #define EOF    -1
  4. #define MAXL    40
  5. extern    float    atof();
  6. extern    char    *ftoa();
  7. extern    int    portc,portd;
  8. main() {
  9.     static float fnuma;
  10.     static    int len;
  11.     static char line[MAXL];
  12.  
  13.     portd = 188;    portc = 189;    /* must be YOUR hardware ports    */
  14.  
  15.     while(len = getline(line, MAXL) < MAXL ) {
  16.         fnuma = atof(line);
  17.  
  18.         printf("%-20.5e\t%-20.5f\t%-20.5g\n",fnuma,fnuma,fnuma);
  19.         printf("%-20.4e\t%-20.4f\t%-20.4g\n",fnuma,fnuma,fnuma);
  20.         printf("%-20.3e\t%-20.3f\t%-20.3g\n",fnuma,fnuma,fnuma);
  21.         printf("%-20.2e\t%-20.2f\t%-20.2g\n",fnuma,fnuma,fnuma);
  22.         printf("%-20.1e\t%-20.1f\t%-20.1g\n",fnuma,fnuma,fnuma);
  23.         printf("\n\n");
  24.     }
  25. }
  26.  
  27. getline(s,lim)    /* get line into s, return length */
  28. char    s[];
  29. int    lim;
  30. {
  31.     int    c,i;
  32.     i = 0;
  33.     while(--lim > 0 && (c=getchar()) != EOF && c != '\n')
  34.         s[i++] = c;
  35.     if (c == '\n')
  36.         s[i++] = c;
  37.     s[i] ='\0';
  38.     return(i);
  39. }
  40. ┴ß╤╒σ┼├■ ┌_┴╤ßσ╒┼├    +σ!9~■
  41. ┬ëσ!π~■b╩å!â┬ä>ß├ë6ß>
  42. *┼    wπσσ`i#═ß»╛ß┬╖┴╤╒┼╒%,σ!σ═╞┴┴┴|╡!  ╚