c-first-steps

a C playground
Index Commits Files Refs README
commit 96aa683696357921383a14cb3686f7ad58b6b81c
parent 8edc12bf7f2995effb3a1b22d62607ff39d55cdf
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Wed, 25 Nov 2020 23:38:46 -0300

Added ex21.c

Diffstat:
A95.11/guia03/ex21.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/95.11/guia03/ex21.c b/95.11/guia03/ex21.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_LEN 100
+
+int main ( void ) {
+
+    char buffer[MAX_LEN];
+    float num;
+    char num2[MAX_LEN];
+
+    if(fgets(buffer, MAX_LEN, stdin) == NULL)
+        return 1;
+
+    num = atof(buffer);
+    sprintf(num2, "%.2f\n", num);
+
+    printf("%s", num2);
+    return 0;
+}