commit d997d509e67a222685efcd992efcbcecf492ebb2
parent 68efa97f64984fc3054fbfccb3229f9d45dc29ca
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date: Wed, 25 Nov 2020 23:57:43 -0300
Added ex23_imp.c "improved" version of ex23.c, checks the sign of the
entered number and prints an error in case of being negative.
Diffstat:
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/95.11/guia03/ex23_beta.c b/95.11/guia03/ex23_beta.c
@@ -1,21 +0,0 @@
-#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;
-
-// Converts the input str to int;
- num = atoi(buffer);
-
-// prints the integer in octal base;
- printf("%o\n", num);
- return 0;
-}
diff --git a/95.11/guia03/ex23_imp.c b/95.11/guia03/ex23_imp.c
@@ -0,0 +1,24 @@
+#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;
+
+// Converts the input str to int;
+ if( (num = atoi(buffer)) < 0 ) {
+ fprintf(stderr, "Debe ingresar un entero positivo!\n");
+ return 1;
+ }
+
+// prints the integer in octal base;
+ printf("%o\n", num);
+ return 0;
+}