home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol7n03.zip / PP703.ZIP / ATOX.C < prev    next >
C/C++ Source or Header  |  1987-12-15  |  1KB  |  36 lines

  1. /*
  2.         ATOX.C  --- a demonstration of the C functions
  3.                     'atoi', 'atol', and 'atof'.
  4.         Ray Duncan, October 1987
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.                 
  10. main(int argc,char *argv[])
  11. {   char buff[80];              /* keyboard input buffer */
  12.     int ivar;                   /* an integer variable */
  13.     long lvar;                  /* a long integer variable */
  14.     double xvar;                /* a floating point variable */
  15.  
  16.     while(1)
  17.     {                           /* display prompt */
  18.        printf("\nEnter a number (Q to quit):  ");
  19.  
  20.        gets(buff);              /* read string from keyboard */
  21.         
  22.                                 /* exit if 'Q' or 'q' entered */
  23.        if( buff[0] == 'Q' || buff[0] == 'q') break;     
  24.  
  25.                                 /* convert in various ways */
  26.        ivar=atoi(buff);         /* string to int */
  27.        lvar=atol(buff);         /* string to long int */
  28.        xvar=atof(buff);         /* string to double prec. real */
  29.  
  30.                                 /* now display results */
  31.        printf("\n\t atoi(your entry) = %d ", ivar);
  32.        printf("\n\t atol(your entry) = %ld ", lvar);
  33.        printf("\n\t atof(your entry) = %e \n", xvar);
  34.     }
  35. }
  36.