commit 5ea06066e933f998baf70dc990f3fea7f82f8b20
parent 38da0843026c71ec0d065c62c0538c2fade63107
Author: klewer-martin <martin.cachari@gmail.com>
Date: Mon, 8 Feb 2021 03:14:22 -0300
Update: Solved bug when printing monthly_infected per country;
Diffstat:
4 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/input.csv b/input.csv
@@ -2,9 +2,12 @@ PAIS, FECHA, INFECTADOS
32,1577880000,2342
32,1578657600,4923
32,1579089600,9324
+32,1579089600,9324
170,1577880000,8234
170,1578657600,9234
170,1579089600,9423
+170,1579089600,9423
276,1577880000,8432
276,1579089600,9129
276,1579521600,4214
+276,1579521600,4214
diff --git a/main.c b/main.c
@@ -73,9 +73,9 @@ int main(int argc, char * argv[])
size_t line;
for(line = 0; (st = read_file(fpi, &country, &date, &infected)) == OK; line++) {
- if(line != 0)
+ if(line != 0) {
print_file(fpo, country_codes, &country, &date, &infected);
-
+ }
st = OK;
}
@@ -83,6 +83,7 @@ int main(int argc, char * argv[])
return st;
fprintf(fpo, "Infectados por mes: %lu\n", infected_monthly);
+ fprintf(fpo, "-------------------------\n\n");
fclose(fpi);
fclose(fpo);
diff --git a/output.txt b/output.txt
@@ -10,7 +10,12 @@ Pais: Argentina
Fecha: 15 Jan 2020
Infectados: 9324
-Infectados por mes: 16589
+Pais: Argentina
+Fecha: 15 Jan 2020
+Infectados: 9324
+
+Infectados por mes: 25913
+-------------------------
Pais: Colombia
Fecha: 01 Jan 2020
@@ -24,7 +29,12 @@ Pais: Colombia
Fecha: 15 Jan 2020
Infectados: 9423
-Infectados por mes: 35246
+Pais: Colombia
+Fecha: 15 Jan 2020
+Infectados: 9423
+
+Infectados por mes: 36314
+-------------------------
Pais: Germany
Fecha: 01 Jan 2020
@@ -38,4 +48,10 @@ Pais: Germany
Fecha: 20 Jan 2020
Infectados: 4214
-Infectados por mes: 48589
+Pais: Germany
+Fecha: 20 Jan 2020
+Infectados: 4214
+
+Infectados por mes: 25989
+-------------------------
+
diff --git a/print_file.c b/print_file.c
@@ -18,15 +18,17 @@ status_t print_file(FILE *dest, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENG
}
// Imprime la suma de infectados por mes cada vez que cambia el pais;
- if(*(country) == prev_country && month == prev_month) {
+ if((*(country) == prev_country) && (month == prev_month)) {
infected_monthly += *(infected);
}
else if(*(country) != prev_country || month != prev_month) {
- fprintf(dest, "Infectados por mes: %lu\n\n", infected_monthly);
+ fprintf(dest, "Infectados por mes: %lu\n", infected_monthly);
+ fprintf(dest, "-------------------------\n\n");
+ infected_monthly = *(infected);
+
prev_country = *(country);
}
-
// Imprime datos segun el archivo de entrada;
fprintf_country(dest, *(country), country_codes);
fprintf_date(dest, *(date));