1 /* Reads a string of chars from stdin and converts 2 it to a number, int or float; */ 3 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 #define MAX_LEN 26 8 9 int 10 main (void) 11 { 12 char buffer[MAX_LEN]; 13 int num1; 14 float num2; 15 16 if(!fgets(buffer, MAX_LEN, stdin)) return 1; 17 num1 = atoi(buffer); 18 printf("n1(int) = %d\n", num1); 19 20 if(!fgets(buffer, MAX_LEN, stdin)) return 1; 21 num2 = atof(buffer); 22 printf("n2(float) = %.2f\n", num2); 23 24 return 0; 25 }