c-first-steps

a C playground
Index Commits Files Refs README
commit 501da762777f4a9706ca41d86941689a3035b483
parent b9fdbd73357c92fd26635b75f77176f658b713aa
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Thu, 19 Nov 2020 11:19:10 -0300

Added ex13.c

Diffstat:
A95.11/guia03/ex13.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/95.11/guia03/ex13.c b/95.11/guia03/ex13.c
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#define MSG_STR_PROMPT    "Introduzca una cadena:"
+#define MSG_FMT_PROMPT    "Convertir a: (0 - MAYUSCULAS / 1 - MINUSCULAS)"
+#define MSG_FMT_ERR        "Err: Formato incorrecto"
+
+#define MAX_STR_LEN 100
+
+typedef enum {
+    FMT_MAYUSCULAS, FMT_MINUSCULAS
+} format_t;
+
+
+int main ( void ) {
+
+
+    char buffer[MAX_STR_LEN];
+    char str[MAX_STR_LEN];
+    format_t format;
+
+
+    printf(MSG_STR_PROMPT"\n>> ");
+    fgets(buffer, MAX_STR_LEN, stdin);
+    strcpy(str, buffer);
+
+    printf(MSG_FMT_PROMPT"\n>> ");
+    format = (getchar () - '0');
+    if((format < 0) || (format > 1)) {
+        fprintf(stderr, MSG_FMT_ERR"\n");
+        return 1;
+    }
+
+    printf("La cadena ingresada: %sOpcion elegida: %d\n", str, format);            
+
+    int i, aux;
+    switch(format)
+    {
+        case FMT_MAYUSCULAS: 
+            for(i = 0; (aux = str[i]) != '\n'; i++) {
+                if(islower(aux))
+                    str[i] = toupper(aux);
+            }
+            break;
+        case FMT_MINUSCULAS:
+            for(i = 0; (aux = str[i]) != '\n'; i++) {
+                if(isupper(aux))
+                    str[i] = tolower(aux);
+            }
+            break;
+    }
+
+    printf("%s", str);
+    return 0;
+}