/* * program to show how atol/atof work * enter number when prompted * * Matt Bishop, ECS 36A, Fall Quarter 2019 */ #include #include #include /* * MACRO -- SIZE OF INPUT BUFFER */ #define BUFFERSIZE 1024 /* * main routine */ int main(int argc, char *argv[]) { char buf[BUFFERSIZE]; /* input buffer */ long i; /* integer read in */ double f; /* double read in */ /* * read in a line and process it */ printf("> "); while(fgets(buf, BUFFERSIZE, stdin) != NULL){ /* clobber the trailing newline to keep the output clean */ if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; /* convert to integer and print it */ i = atol(buf); printf("\'%s\' is the integer %ld\n", buf, i); /* convert to double and print it */ f = atof(buf); printf("\'%s\' is the double %f\n", buf, f); printf("> "); } /* clean up the end of the output */ putchar('\n'); /* * done! */ return(0); }