9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 59c62735f12eb3c856905ce1ebf6471e54642be7
parent 79b3cbe20b9bd6c737602b65dd88fb301c42b870
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Wed,  3 Feb 2021 13:02:28 -0300

Update on readlines.c, making cleaner, adding more comments;

Diffstat:
Minput.csv | 377+------------------------------------------------------------------------------
Mmain.c | 18++++++++++++------
Mreadlines.c | 49++++++++++++++++++++++++++++++++-----------------
Mreadlines.h | 2+-
4 files changed, 46 insertions(+), 400 deletions(-)
diff --git a/input.csv b/input.csv
@@ -1,365 +1,5 @@
 PAIS, FECHA, INFECTADOS
 32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1577880000,2342
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1577880000,2342
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
 32,1578657600,4923
 32,1579089600,9324
 170,1577880000,8234
@@ -367,19 +7,4 @@ PAIS, FECHA, INFECTADOS
 170,1579089600,9423
 276,1577880000,8432
 276,1579089600,9129
-276,1579521600,4214 
-834,1577880000,8432
-764,1579089600,9129
-704,1579521600,4214 
-504,1577880000,2342
-104,1578657600,4923
-480,1579089600,9324
-484,1577880000,8234
-496,1578657600,9234
-554,1579089600,9423
-558,1577880000,8432
-574,1579089600,9129
-512,1579521600,4214 
-586,1577880000,8432
-591,1579089600,9129
-384,1579521600,4214 
+276,1579521600,4214
diff --git a/main.c b/main.c
@@ -30,25 +30,31 @@ int main(int argc, char * argv[])
 //    caso de que haya alguno;
     status_t st;
 
+//    Las siguientes variables son para guardar los nombres de los archivos de 
+//    entrada y salida luego de validar que los argumentos recibidos sean correctos;
     char src[32], dest[32];
 
+//    El siguiente arreglo de dos dimensiones es donde se van a guardar los codigos
+//    de los paises;
     char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
 
-//    char **country_codes = (char**)malloc(COUNTRIES_NUMBER * ARRAYS_LENGTH * sizeof(char));
-
+//    Valida de que los argumentos sean correctos y guarda los nombres de los
+//    archivos de entrada y salida en src y dest respectivamente, de haber algun
+//    error en el proceso devuelve un codigo de error de tipo status_t (definido 
+//    en main.h);
     if((st = validate_arguments(argc, argv, src, dest)) != OK) {
         print_error(st);
         return st;
     }
     
 
+//    Carga los codigos de error de los paises de acuerdo al standard iso3166 en el
+//    arreglo mencionado previamente 'country_codes', en caso de haber algun error 
+//    en el proceso devuelve dicho codigo e impreme por stderr un mensaje de error; 
     if(load_country_codes(country_codes) != OK)
         return ERROR_LOADING_COUNTRY_CODES;    
 
-
-    putchar('\n');
-
-    readlines();
+    readlines(src, dest);
 
     return OK;
 }
diff --git a/readlines.c b/readlines.c
@@ -1,15 +1,25 @@
+//    Lee el archivo de entrada 
+
+
+
 #include "readlines.h"
 
 #define COUNTRY_PROMPT "Pais"
 
 const char date_print_format[] = "%d %b %Y";
 
-status_t readlines(void)
+status_t readlines(char *src, char *dest)
 {
     size_t line, i, j;
+
+//    Puntero para el archivo de entrada;    
     FILE *fp;
+
     char buff1[] = "                          ";
     char buff2[] = "                          ";
+
+//    Esta variable es para saber de que tipo de dato estamos hablando, si es un
+//    codigo de pais, una fecha o el numero de infectados;
     data_t data;
 
     char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
@@ -19,15 +29,27 @@ status_t readlines(void)
     unsigned long date;
     unsigned long infected;
 
-    if((fp = fopen(INPUT_FILE_NAME, "r")) == NULL)
+
+// Abre el archivo de entrada en modo lectura si por algun motivo no se puede
+// abrir devuelve un codigo de error;
+    if((fp = fopen(src, "r")) == NULL)
             return ERROR_READING_FILE;
 
+
+//    Lee de el archivo de entrada linea por linea y va guardando las 
+//    lineas en buff1 hasta que se terminen;
     for(line = 0; fgets(buff1, sizeof(buff1), fp) != NULL; line++)
     {
-//    This 'if' is to skip the first line which doesn't contain information;
+
+//    Este 'if' es para evitar la primer linea que no contiene ningun tipo de dato;
         if(line != 0) {
+
+//            Recorre el buff1 separando los datos de acuerdo a si es el codigo de
+//            un pais, una fecha o el numero de infectados;
             for(i = 0, j = 0, data = PAIS; buff1[i] != '\0'; i++)
             {
+
+//                Si encuentra una coma cambia el tipo de dato;
                 if((buff1[i] == ',') || (buff1[i] == '\n'))
                 {
                     i++;
@@ -40,6 +62,7 @@ status_t readlines(void)
                     data++;
                     j = 0;
                     clean_buffer(buff2);
+                    printf("data: %d\n", data);
                 }
 
                 switch(data) 
@@ -50,23 +73,12 @@ status_t readlines(void)
 
                 }
             }
-            print_country(country, country_codes);
-            print_date(date);
-            print_infected(infected);
+//            print_country(country, country_codes);
+//            print_date(date);
+//            print_infected(infected);
         }
     }
 
-//    char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
-
-//    if(load_country_codes(country_codes) != OK)
-//        return ERROR_LOADING_COUNTRY_CODES;
-//    empty_country_codes(country_codes);
-
-//    size_t i;
-//    for(i = 0; i < 500; i++)
-//        printf("%s", *(country_codes + i));
-
-
     fclose(fp);
     return OK;
 }
@@ -75,6 +87,9 @@ status_t readlines(void)
 
 status_t print_country(size_t country_code, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
 {
+    if(country_codes == NULL)
+        return ERROR_NULL_POINTER;
+
     printf(COUNTRY_PROMPT": %s\n", country_codes[country_code]);
     return OK;
 }
diff --git a/readlines.h b/readlines.h
@@ -19,7 +19,7 @@ typedef enum {
 } data_t;
 
 
-status_t readlines(void);
+status_t readlines(char *src, char *dest);
 status_t print_date(size_t data);
 status_t print_infected(size_t data);
 status_t clean_buffer(char *buffer);