9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 6324e62dbf15a73fe5380bb7ba0ca7c77818c803
parent 5b0c7727acfbfbabaa92c98e9fcbfd05bdb53ab2
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Mon, 31 May 2021 13:15:03 -0300

Update: corrected conditions like comparisons with 0, and comments made with '//'

Diffstat:
Mguia03/ex11.c | 12++++--------
Mguia03/ex12.c | 6+++---
Mguia03/ex13.c | 28++++++++++++----------------
3 files changed, 19 insertions(+), 27 deletions(-)
diff --git a/guia03/ex11.c b/guia03/ex11.c
@@ -3,17 +3,13 @@
 
 int main(void) 
 {
+    int i, aux;
     char str[] = "hello world";
-    int i;
-    char aux;
 
-    for(i = 0; (aux = str[i]) != '\0'; i++)
-        if(islower(aux))
-            str[i] = toupper(aux);
+    for(i = 0; aux = str[i]; i++)
+        if((aux < 123) && (aux > 96))
+            str[i] = (aux - 32);
 
     printf("%s\n", str);
     return 0;
 }
-
-
-
diff --git a/guia03/ex12.c b/guia03/ex12.c
@@ -7,9 +7,9 @@ int main(void)
     int i;
     char aux;
 
-    for(i = 0; (aux = str[i]) != '\0'; i++)
-        if(isupper(aux))
-            str[i] = tolower(aux);
+    for(i = 0; aux = str[i]; i++)
+        if((aux > 64) && (aux < 91))
+            str[i] = aux + 32;
 
     printf("%s\n", str);
     return 0;
diff --git a/guia03/ex13.c b/guia03/ex13.c
@@ -1,6 +1,5 @@
-//    Reads a string from stdin and converts it to uppercase or lowercase 
-//    depending on an option readed from stdin
-
+/*    Reads a string from stdin and converts it to uppercase or lowercase 
+ *     depending on an option readed from stdin    */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -18,41 +17,38 @@ typedef enum {
 } format_t;
 
 
-int main ( void ) {
-
-
+int
+main (void)
+{
     char buffer[MAX_STR_LEN];
     char str[MAX_STR_LEN];
     format_t format;
 
-
-    printf(MSG_STR_PROMPT"\n>> ");
+    printf("%s%s", MSG_STR_PROMPT, "\n>> ");
     fgets(buffer, MAX_STR_LEN, stdin);
     strcpy(str, buffer);
 
-    printf(MSG_FMT_PROMPT"\n>> ");
+    printf("%s%s", MSG_FMT_PROMPT, "\n>> ");
     format = (getchar () - '0');
     if((format < 0) || (format > 1)) {
-        fprintf(stderr, MSG_FMT_ERR"\n");
+        fprintf(stderr, "%s\n", MSG_FMT_ERR);
         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++) {
+            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++) {
+            for(i = 0; (aux = str[i]) != '\n'; i++)
                 if(isupper(aux))
                     str[i] = tolower(aux);
-            }
+
             break;
     }