c-first-steps

a C playground
Index Commits Files Refs README
commit 5c9808785b68ed51c3b26dc021ca0655a38ea66c
parent 30e257163a1d7bc583811d57b148c48ac5da817a
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Sat, 14 Nov 2020 12:33:28 -0300

Reorganized directories & added ej9.c

Diffstat:
Aguia02/a.out | 0
Aguia02/ej1.c | 16++++++++++++++++
Aguia02/ej2.c | 21+++++++++++++++++++++
Aguia02/ej3.c | 15+++++++++++++++
Aguia02/ej4.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aguia02/ej5.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aguia02/ej6.c | 27+++++++++++++++++++++++++++
Aguia02/ej7.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aguia02/ej7_2.c | 42++++++++++++++++++++++++++++++++++++++++++
Aguia02/ej8.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aguia02/guia02.pdf | 0
11 files changed, 397 insertions(+), 0 deletions(-)
diff --git a/guia02/a.out b/guia02/a.out
Binary files differ.
diff --git a/guia02/ej1.c b/guia02/ej1.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+typedef enum {
+        FALSE,
+        TRUE
+} bool_t; 
+
+int main(void)
+{
+    bool_t isworking = TRUE;
+    printf("%s\n", isworking ? "TRUE" : "FALSE");
+
+    return 0;
+}
+
+
diff --git a/guia02/ej2.c b/guia02/ej2.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+typedef enum {
+        ERROR,
+        OK
+} status_t; 
+
+int main(void)
+{
+
+    status_t isworking = OK;
+
+    if (isworking == 1)
+        printf("OK\n");
+    else
+        printf("ERROR\n");
+
+    return 0;
+}
+
+
diff --git a/guia02/ej3.c b/guia02/ej3.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+typedef enum {
+    LUN, MAR, MIE, JUE, VIE, SAB, DOM
+} dia_t;
+
+int main(void)
+{
+    dia_t dia = VIE;
+
+    printf("%d\n", dia);
+    
+
+    return 0;
+}
diff --git a/guia02/ej4.c b/guia02/ej4.c
@@ -0,0 +1,79 @@
+/*    Ejercicio 4 - Guia 2, Algoritmos y Programacion I - FIUBA    */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_INP_LEN 10
+
+typedef enum {
+    FAHRENHEIT,
+    CELSIUS
+} escala_t;
+
+typedef float dato_t;    
+                    
+dato_t ftoc(dato_t fahrenheit)
+{
+    return (((fahrenheit - 32) *5 ) / 9);
+}
+
+dato_t ctof(dato_t celsius)
+{
+    return (((celsius * 9) / 5) + 32);
+}
+
+void title(int i)
+{
+    printf(
+        "---------------------------------------\n"
+        "---------------------------------------\n"
+        "--- %s TO %s CONVERTER ---\n"
+        "---------------------------------------\n"
+        "---      to exit press Ctrl+D      ----\n"
+        "---------------------------------------\n"
+        "---------------------------------------\n",
+        i ? "CELSIUS" : "FAHRENHEIT",
+        i ? "FAHRENHEIT" : "CELSIUS"
+    );
+}
+
+void cursor()
+{
+    printf(">> ");
+}
+
+
+
+int main(void)
+{
+    char buffer[MAX_INP_LEN];
+    escala_t c;
+    dato_t i, res;
+    printf("0 - FAHRENHEIT TO CELSIUS\n");
+    printf("1 - CELSIUS TO FAHRENHEIT\n");
+    cursor();
+    c = getchar() - '0';
+    if (c == FAHRENHEIT) {
+        title(FAHRENHEIT);
+        while (fgets(buffer, MAX_INP_LEN, stdin) != NULL) {
+            i = atoi(buffer);
+            res = ftoc(i);
+            printf("%.0f°F = %.2f°C\n", i, res);
+            cursor();
+        }
+    } else if (c == CELSIUS) {
+        title(CELSIUS);
+        while (fgets(buffer, MAX_INP_LEN, stdin) != NULL) {
+            i = atoi(buffer);
+            res = ctof(i);
+            printf("%.0f°C = %.2f°F\n", i, res);
+            cursor();
+        }
+    }
+    printf("\n");
+    return 0;
+}
+
+
+
diff --git a/guia02/ej5.c b/guia02/ej5.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+
+typedef enum {
+    JAN, FEB, MAR, APR, MAY, JUN, JUL, AGO, SEP, OCT, NOV, DEC
+} mes_t;
+
+#define JANUARY        "ENERO\n"
+#define FEBRUARY    "FEBRERO\n"
+#define MARCH         "MARZO\n"
+#define APRIL        "ABRIL\n"
+#define MAYO        "MAYO\n"
+#define JUNE        "JUNIO\n"
+#define JULY        "JULIO\n"
+#define AUGUST        "AGOSTO\n"
+#define SEPTEMBER    "SEPTIEMBRE\n"
+#define OCTOBER        "OCTUBRE\n"
+#define NOVEMBER    "NOVIEMBRE\n"
+#define DECEMBER    "DICIEMBRE\n"
+
+int main(void) {
+    mes_t mes = NOV;
+    switch(mes)
+    {
+        case JAN:
+            printf(JANUARY);
+            break;
+        case FEB:
+            printf(FEBRUARY);
+            break;
+        case MAR:
+            printf(MARCH);
+            break;
+        case APR:
+            printf(APRIL);
+            break;
+        case MAY:
+            printf(MAYO);
+            break;
+        case JUN:
+            printf(JUNE);
+            break;
+        case JUL:
+            printf(JULY);
+            break;
+        case AGO:
+            printf(AUGUST);
+            break;
+        case SEP:
+            printf(SEPTEMBER);
+            break;
+        case OCT:
+            printf(OCTOBER);
+            break;
+        case NOV:
+            printf(NOVEMBER);
+            break;
+        case DEC:
+            printf(DECEMBER);
+            break;
+    }    
+    return 0;
+}
diff --git a/guia02/ej6.c b/guia02/ej6.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <ctype.h>
+
+int main(void)
+{
+    int alpha, nonalpha, num;
+    int c;
+    
+    alpha = nonalpha = num = 0;
+
+    while((c = getchar()) != EOF ) {
+        if(isalpha(c))
+            alpha++;
+        else if(isdigit(c))
+            num++;
+        else if(!isalnum(c))
+            nonalpha++;
+    }
+    printf(
+        "Alphanumerics: %d\n"
+        "NonAlphanumerics: %d\n"
+        "Digits: %d\n",
+        alpha, nonalpha, num
+    );
+
+    return 0;
+}
diff --git a/guia02/ej7.c b/guia02/ej7.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define MAX_LEN 5    // max digits of the entered degree;
+#define ERR_MSG_LEN "El angulo ingresado contiene demasiados digitos"
+
+typedef enum {
+    AGUDO, OBTUSO, RECTO
+} angulo_t;
+
+
+void clean(char *buffer)
+{
+    for(size_t i = 0; i < MAX_LEN; i++)
+        buffer[i] = '\0';
+}
+
+
+int main(void) {
+    
+    char buffer[MAX_LEN];
+    clean(buffer);
+    int c, d, e, i;
+    i = 0;        
+    while(((c = getchar()) != EOF) && c != '\n') {
+        if(i < MAX_LEN) {
+            buffer[i] = c;
+            i++;
+        } else if (i >= MAX_LEN) {
+            fprintf(stderr, ERR_MSG_LEN"\n");
+            return 1;
+        }
+    }
+    d = atoi(buffer);
+
+    if (d < 90)
+        e = AGUDO;
+    else if (d == 90)
+        e = RECTO;
+    else if (d > 90)
+        e = OBTUSO;
+
+
+    switch (e)
+    {
+        case AGUDO:
+            printf("El angulo es AGUDO\n");
+            break;
+        case RECTO:
+            printf("El angulo es RECTO\n");
+            break;
+        case OBTUSO:
+            printf("El angulo es OBTUSO\n");
+            break;
+    }
+    return 0;
+}
+
+
+
+
diff --git a/guia02/ej7_2.c b/guia02/ej7_2.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define MAX_LEN 5    // max digits of the entered degree;
+#define ERR_MSG_LEN "El angulo ingresado contiene demasiados digitos"
+
+typedef enum {
+    AGUDO, OBTUSO, RECTO
+} angulo_t;
+
+void clean(char *buffer)
+{
+    for(size_t i = 0; i < MAX_LEN; i++)
+        buffer[i] = '\0';
+}
+
+
+int main(void) {
+    
+    char buffer[MAX_LEN];
+    int c, d, i;
+    i = 0;
+
+    while((c = getchar()) != EOF) {
+        if(c != '\n') {
+            if(i < MAX_LEN) {
+                buffer[i] = c;
+                i++;
+            } else if(i > MAX_LEN) {
+                fprintf(stderr, ERR_MSG_LEN"\n");
+                return 1;
+            }
+        }
+    i = 0;
+    d = atoi(buffer);
+    printf("%d\n", d);
+    clean(buffer);
+    }
+
+    return 0;
+}
diff --git a/guia02/ej8.c b/guia02/ej8.c
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define MAX_LEN 5    // max digits of the entered degree;
+#define ERR_MSG_LEN "El angulo ingresado contiene demasiados digitos"
+
+#define FST_YR 48
+#define SND_YR 95
+#define TRD_YR 143
+
+
+typedef enum {
+    FIRST, SECOND, THIRD, FOURTH
+} year_t;
+
+
+void clean(char *buffer)
+{
+    for(size_t i = 0; i < MAX_LEN; i++)
+        buffer[i] = '\0';
+}
+
+
+int main(void) {
+    
+    char buffer[MAX_LEN];
+    clean(buffer);
+    int c, d, i;
+    year_t e;
+    i = 0;        
+    while(((c = getchar()) != EOF) && c != '\n') {
+        if(i < MAX_LEN) {
+            buffer[i] = c;
+            i++;
+        } else if (i >= MAX_LEN) {
+            fprintf(stderr, ERR_MSG_LEN"\n");
+            return 1;
+        }
+    }
+    d = atoi(buffer);
+
+    if (d <= FST_YR) 
+        e = FIRST;
+    else if ((d > FST_YR) && (d <= SND_YR))
+        e = SECOND;
+    else if ((d > SND_YR) && d <= (TRD_YR))
+        e = THIRD;
+    else if (d > TRD_YR) 
+        e = FOURTH;
+
+
+    switch (e)
+    {
+        case FIRST:
+            printf("Primer año\n");
+            break;
+        case SECOND:
+            printf("Segundo año\n");
+            break;
+        case THIRD:
+            printf("Tercer año\n");
+            break;
+        case FOURTH:
+            printf("Curto año o superior\n");
+            break;
+    }
+    return 0;
+}
+
+
+
+
diff --git a/guia02/guia02.pdf b/guia02/guia02.pdf
Binary files differ.