c-first-steps

a C playground
Index Commits Files Refs README
commit ed3d5deeede0c2b1b71ea07bec7f8022890387e1
parent c9bc9bbc69486fb6ffe1f2753ed9829104f4509d
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Wed, 25 Nov 2020 23:48:56 -0300

Added ex23.c

Diffstat:
A95.11/guia03/ex23.c | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/95.11/guia03/ex23.c b/95.11/guia03/ex23.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_LEN 100
+
+int main ( void ) {
+
+    char buffer[MAX_LEN];
+    int num;
+    char num2[MAX_LEN];
+
+    if(fgets(buffer, MAX_LEN, stdin) == NULL)
+        return 1;
+
+    num = atoi(buffer);
+
+//    Converts num to octal and stores it on num2 str;
+    sprintf(num2, "%o\n", num);
+
+//    prints the string with the octal number;
+    printf("%s", num2);
+    return 0;
+}