home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C by Discovery (4th Edition)
/
C_By_Discovery_4th_Edition.tar
/
C_By_Discovery_4th_Edition
/
_DISK_
/
ch11
/
convert.c
< prev
next >
Wrap
C/C++ Source or Header
|
2005-06-16
|
841b
|
29 lines
/* convert.c
*
* Synopsis - Accepts the input of a string of digits and
* converts those digits to a decimal integer.
* Objective - To show the use of the facility isdigit() in
* validating input.
*/
/* Include Files */
#include <stdio.h>
#include <ctype.h> /* Note 1 */
/* Constant Definitions */
#define BUF_SIZE 80
int main( void )
{
int index = 0, num = 0;
char inbuff[BUF_SIZE];
printf( "Enter a string of decimal digits: " );
fgets( inbuff, BUF_SIZE, stdin );
while ( isdigit( inbuff[index] )) /* Note 2 */
/* Note 3 */
num = 10*num + inbuff[index++] - '0';
printf( "That number is %d.\n", num );
return 0;
}