home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast.iso
/
pcmag
/
vol7n03.zip
/
PP703.ZIP
/
ATOX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-12-15
|
1KB
|
36 lines
/*
ATOX.C --- a demonstration of the C functions
'atoi', 'atol', and 'atof'.
Ray Duncan, October 1987
*/
#include <stdio.h>
#include <stdlib.h>
main(int argc,char *argv[])
{ char buff[80]; /* keyboard input buffer */
int ivar; /* an integer variable */
long lvar; /* a long integer variable */
double xvar; /* a floating point variable */
while(1)
{ /* display prompt */
printf("\nEnter a number (Q to quit): ");
gets(buff); /* read string from keyboard */
/* exit if 'Q' or 'q' entered */
if( buff[0] == 'Q' || buff[0] == 'q') break;
/* convert in various ways */
ivar=atoi(buff); /* string to int */
lvar=atol(buff); /* string to long int */
xvar=atof(buff); /* string to double prec. real */
/* now display results */
printf("\n\t atoi(your entry) = %d ", ivar);
printf("\n\t atol(your entry) = %ld ", lvar);
printf("\n\t atof(your entry) = %e \n", xvar);
}
}