9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 35ba81de8e50d0c549ccd188c4cc096f0f9e1ad5
parent 4b0925ea957fc126b31558a9ee1440b91b9594b6
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Wed,  3 Feb 2021 11:51:07 -0300

Update to source code, now with more comments and more clean;

Diffstat:
Minput.csv | 360+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mload_country_codes.c | 25++++++++++++++++++-------
Mmain.c | 33++++++++++++++++++++++++++++-----
Aoutput.csv | 0
4 files changed, 406 insertions(+), 12 deletions(-)
diff --git a/input.csv b/input.csv
@@ -1,5 +1,365 @@
 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
diff --git a/load_country_codes.c b/load_country_codes.c
@@ -1,11 +1,20 @@
+// Carga en memoria los codigos de los paises de el archivo de nombre 
+// "COUNTRY_CODES_FILE_NAME" definido en macros.h y devuelve un puntero
+// a dicho arreglo con los codigos cargados;
+
+
 #include "main.h"
 #include "macros.h"
 #include "load_country_codes.h"
 
 status_t clean (char *buffer, size_t size)
 {
-    size_t i;
+    size_t i;
     i = 0;
+
+    if(buffer == NULL)
+        return ERROR_NULL_POINTER;
+
     while(i < size) {
         buffer[i] = '\0';
         i++;
@@ -13,7 +22,7 @@ status_t clean (char *buffer, size_t size)
     return OK;
 }
 
-
+//    Inicializa el arreglo alocando el caracter '\0' en todas las posiciones;
 status_t empty_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]) 
 {
     size_t i, j;
@@ -27,6 +36,12 @@ status_t empty_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]
     return OK;
 }
 
+
+// Abre el archivo "COUNTRY_CODES_FILE_NAME" y lee linea por linea hasta llegar
+// al final, mientras lee lo va guardando en un buffer que recorre caracter por
+// caracter en busqueda de el character separador de datos, en este caso ',', 
+// mientras recorre el buffer va separando los datos y los guarda en la variable
+// que corresponda;
 status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
 {
     FILE *fp;
@@ -68,15 +83,11 @@ status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
             }
         }
         country_code = atoi(buff_2);
-//        printf("%d\n", country_code);
         clean(buff_2, INITIAL_SIZE);
-
-
-//        printf("%s\n", country_name);
         strcpy(country_codes[country_code], country_name);
-//        printf("n. %d is: %s\n", country_code, country_codes[country_code]);
     }
 
+//    Cierra el archivo que contiene el codigo de los paises de acuerdo al estandar;
     fclose(fp);
     free(buff);
     return OK;
diff --git a/main.c b/main.c
@@ -1,29 +1,52 @@
+//    
+//    Programa escrito por Martin J. Klockner
+//        martin.cachari@gmail.com
+//        github.com/klewer-martin
+//
+//    Repositorio de github del proyecto:
+//            https://github.com/klewer-martin/9511_project01.git
+//            (Disponible a partir de la fecha de correccion)
+            
+
+//    Lee texto de un archivo con extension .csv cuyo nombre recibe 
+//    como argumento; el cual contiene solo numeros que representan 
+//    un pais, una fecha y una cantidad de infectados y lo guarda en
+//    un archivo de extension .csv que tambien recibe como argumento,
+//    si no recibe un archivo de salida crea uno con el nombre por
+//    defecto 'output.csv';
+
+
 #include "main.h"
 #include "arguments.h"
 #include "macros.h"
 #include "load_country_codes.h"
 #include "readlines.h"
 
-#define CANTIDAD_DE_DATOS 3
 
 int main(int argc, char * argv[])
 {
+
+//    Esta variable es para guardar los codigos de error en
+//    caso de que haya alguno;
     status_t st;
+
+    char src[32], dest[32];
+//    char dest[32];
+
+
     FILE *fpi;
 //        , *fpo;
 
     char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
 
+//    char **country_codes = (char**)malloc(COUNTRIES_NUMBER * ARRAYS_LENGTH * sizeof(char));
+
     if((st = validate_arguments(argc, argv)) != OK) {
         print_error(st);
         return st;
     }
     
-    char * src;
-    char * dest;
 
-    src = (char *)malloc(INITIAL_SIZE * sizeof(char));
-    dest = (char *)malloc(INITIAL_SIZE * sizeof(char));
 
     if((st = set_files_name(argc, argv, src, dest)) != OK) {
         print_error(st);
diff --git a/output.csv b/output.csv