◄Up► ◄Contents► ◄Index► ◄Back► ─────Run-Time Library─────────────────────────────────────────────────────── /* ATONUM.C illustrates string-to-number conversion functions including: * atof atoi atol _gcvt * * It also illustrates: * _cgets _cputs */ #include <stdlib.h> #include <string.h> #include <conio.h> #define MAXSTR 100 char cnumbuf[MAXSTR] = { MAXSTR + 2, 0 }; char tmpbuf[MAXSTR]; /* Numeric input and output without printf */ void main() { int integer; long longint; float real; char *numbuf; /* Using _cgets (rather than gets) allows use of DOS editing keys * (or of editing keys from DOS command-line editors). */ _cputs( "Enter an integer: " ); numbuf = _cgets( cnumbuf ); _cputs( "\r\n" ); /* _cputs doesn't translate \n */ integer = atoi( numbuf ); strcpy( tmpbuf, numbuf ); strcat( tmpbuf, " + " ); _cputs( "Enter a long integer: " ); numbuf = _cgets( cnumbuf ); _cputs( "\r\n" ); longint = atol( numbuf ); strcat( tmpbuf, numbuf ); strcat( tmpbuf, " + " ); _cputs( "Enter a floating-point number: " ); numbuf = _cgets( cnumbuf ); _cputs( "\r\n" ); real = (float)atof( numbuf ); strcat( tmpbuf, numbuf ); strcat( tmpbuf, " = " ); _gcvt( integer + longint + real, 4, numbuf ); strcat( tmpbuf, numbuf ); strcat( tmpbuf, "\r\n" ); _cputs( tmpbuf ); } -♦-