9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 78b881612aabd78ffc83454879a0a53bd551f7e2
parent df07e5f9d8d5ca82b0b4c1c1a20829c505cf84e3
Author: Martin J. Klöckner <64109770+klewer-martin@users.noreply.github.com>
Date:   Tue,  9 Feb 2021 17:54:58 -0300

Merge pull request #9 from klewer-martin/beta

Beta
Diffstat:
MMakefile | 12++++++------
MREADME.md | 16++++++++++++++--
Mmain.c | 24++++++++++--------------
Mmain.h | 2--
Mprint_file.c | 2+-
Mread_file.c | 20++++++++++----------
Mread_file.h | 2+-
7 files changed, 42 insertions(+), 36 deletions(-)
diff --git a/Makefile b/Makefile
@@ -8,22 +8,22 @@ main: main.o arguments.o perrors.o load_country_codes.o read_file.o print_file.o
     $(CC) $(CFLAGS) main.o arguments.o perrors.o load_country_codes.o read_file.o print_file.o -o main 
 
 main.o: main.c main.h arguments.h macros.h
-    $(CC) -c main.c
+    $(CC) $(CFLAGS) -c main.c
 
 arguments.o: arguments.c arguments.h macros.h
-    $(CC) -c arguments.c
+    $(CC) $(CFLAGS) -c arguments.c
 
 perrors.o: main.c main.h
-    $(CC) -c perrors.c
+    $(CC) $(CFLAGS) -c perrors.c
 
 load_country_codes.o: load_country_codes.h main.h
-    $(CC) -c load_country_codes.c 
+    $(CC) $(CFLAGS) -c load_country_codes.c 
 
 read_file.o: read_file.h main.h
-    $(CC) -c read_file.c
+    $(CC) $(CFLAGS) -c read_file.c
 
 print_file.o: print_file.h main.h
-    $(CC) -c print_file.c
+    $(CC) $(CFLAGS) -c print_file.c
 
 
 clean:
diff --git a/README.md b/README.md
@@ -7,13 +7,26 @@ runs on CLI which its function is to process data entered via
 a .csv file.
 
 What it does is receive a number for a country, date, and number of
-cases (of COVID19), and prints it on stdout with a human readable
+cases (of COVID19), and prints it on a file with a human readable
 format.
 
 Bibliography:
 
 "The C programming language" - Brian W. Kernighan & Dennis Ritchie.
 
+Linux installation:
+    Arch based distros:
+        .Install base-devel, git(not neccesary unless you want to clone
+         the repo).
+        .Clone repo from terminal or download the .zip file and unzip
+         it.
+        .Navigate to the folder and open a terminal there, run
+        'make install'.
+
+    Debian based distros:
+        .Install gcc
+
+    
 NAME
     analisis_covid - analyze RAW data and export it with a human 
     readable format.
@@ -26,7 +39,6 @@ DESCRIPTION
     Process RAW data from a .csv(comma separated values) file,
     and export it to another .csv file, if the output file doesn't
     exist then it creates one with the specified name.
-
     When you invoke analisis_covid, expects.. to be continued
 
 
diff --git a/main.c b/main.c
@@ -53,10 +53,11 @@ int main(int argc, char * argv[])
         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; 
+    
+//    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((st = load_country_codes(country_codes)) != OK) {
         print_error(st);
         return ERROR_LOADING_COUNTRY_CODES;    
@@ -83,21 +84,16 @@ int main(int argc, char * argv[])
     }
 
     if((st != OK) && (st != END_OF_INPUT_FILE)) {
-        close_files(fpi, fpo);
+        fclose(fpi);
+        fclose(fpo);
         return st;
     }
 
     fprintf_infected_monthly(fpo);
 
-    close_files(fpi, fpo);
-    printf(MSG_OK);
-    return OK;
-}
-
-void close_files(FILE *fpi, FILE *fpo)
-{
     fclose(fpi);
     fclose(fpo);
-}
-
 
+    printf(MSG_OK);
+    return OK;
+}
diff --git a/main.h b/main.h
@@ -46,6 +46,4 @@ typedef enum {
     END_OF_INPUT_FILE,
 } status_t;
 
-void close_files(FILE *fpi, FILE *fpo);
-
 #endif
diff --git a/print_file.c b/print_file.c
@@ -108,7 +108,7 @@ void fprintf_infected_monthly(FILE *dest)
 
 
     fprintf(dest, "Infectados por mes: %lu\n", infected_monthly);    
-    sprintf(str_infected_monthly, "%lu", 10);
+    sprintf(str_infected_monthly, "%u", 10);
     fprintf(dest, "-------------------%.*s\n", (length + 1), guion_medio); 
 
     free(str_infected_monthly);
diff --git a/read_file.c b/read_file.c
@@ -2,15 +2,15 @@
 #include "read_file.h"
 
 
-status_t read_file(FILE *src, u_long *country, u_long *date, u_long *infected)
+status_t read_file(FILE *src, ulong *country, ulong *date, ulong *infected)
 {
 
 //    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;
 
-    size_t line, i, j;
-    status_t st;
+    size_t i, j;
+//    status_t st;
 
     char buff1[SIZE_OF_BUFF1];
     char buff2[SIZE_OF_BUFF2];
@@ -18,7 +18,7 @@ status_t read_file(FILE *src, u_long *country, u_long *date, u_long *infected)
     clean_buffer(buff1, SIZE_OF_BUFF1);
     clean_buffer(buff2, SIZE_OF_BUFF2);
 
-    char time_s[TIME_MAX_DIGITS];
+//    char time_s[TIME_MAX_DIGITS];
 
 //    Lee de el archivo de entrada linea por linea y va guardando las 
 //    lineas en buff1 hasta que se terminen;
@@ -32,12 +32,12 @@ status_t read_file(FILE *src, u_long *country, u_long *date, u_long *infected)
         if((buff1[i] == ','))
         {
             i++;
-            switch(data) 
-            {
-                case PAIS: *(country) = atoi(buff2); break;
-                case DATE: *(date) = atol(buff2); j++; break;
-            }
-
+            if(data == PAIS) 
+                *(country) = atoi(buff2);
+            
+            else if (data == DATE) 
+                *(date) = atol(buff2);
+            
             data++;
             j = 0;
             clean_buffer(buff2, SIZE_OF_BUFF2);
diff --git a/read_file.h b/read_file.h
@@ -10,7 +10,7 @@ typedef enum {
     INFECTED
 } data_t;
 
-status_t read_file(FILE *src, u_long *country, u_long *date, u_long *infected);
+status_t read_file(FILE *src, ulong *country, ulong *date, ulong *infected);
 
 status_t fprintf_date(FILE *dest, size_t data);
 status_t fprintf_infected(FILE *dest, size_t data, char newline);