commit 8edc12bf7f2995effb3a1b22d62607ff39d55cdf
parent 5ce714632a3ef9af95f9e7bc8272856b94756453
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date: Tue, 24 Nov 2020 22:53:39 -0300
Added ex20.c
Diffstat:
1 file changed, 24 insertions(+), 0 deletions(-)
diff --git a/95.11/guia03/ex20.c b/95.11/guia03/ex20.c
@@ -0,0 +1,24 @@
+// Reads a string of chars from stdin and converts
+// it to a number, int or float;
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_LEN 100
+
+int main ( void ) {
+
+ char buffer[MAX_LEN];
+ int num1;
+ float num2;
+
+ fgets(buffer, MAX_LEN, stdin);
+ num1 = atoi(buffer);
+ printf("n1(int) = %d\n", num1);
+
+ fgets(buffer, MAX_LEN, stdin);
+ num2 = atof(buffer);
+ printf("n2(float) = %.2f\n", num2);
+
+ return 0;
+}