commit 850ec30ce69839c00d0165470d03513876ea4102
parent 249ec1ae34e4389b8a9a588dc8f61447af644919
Author: klewer-martin <martin.cachari@gmail.com>
Date: Fri, 16 Apr 2021 20:11:37 -0300
Update;
Diffstat:
4 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/load_country_codes.c b/load_country_codes.c
@@ -16,20 +16,22 @@ status_t load_country_codes(char **country_codes)
char buff2[INITIAL_SIZE];
buff2[INITIAL_SIZE] = '\0';
- int country_code;
+ clean(buff2, INITIAL_SIZE);
+
+ int country_code = 0;
char country_name[INITIAL_SIZE];
country_name[INITIAL_SIZE - 1] = '\0';
size_t i, j;
part_t part;
- buff = (char *)malloc(INITIAL_SIZE);
+ buff = (char *)malloc(INITIAL_SIZE * sizeof(char));
if((fp = fopen(COUNTRY_CODES_FILE_NAME, "r")) == NULL) {
+ free(buff);
return ERROR_LOADING_COUNTRY_CODES;
}
-
while(fgets(buff, INITIAL_SIZE, fp) != NULL) {
clean(country_name, INITIAL_SIZE);
for(i = 0, j = 0, part = CODE; buff[i] != '\0'; i++) {
@@ -80,7 +82,7 @@ status_t empty_country_codes(char **country_codes)
size_t i, j;
for(i = 0; i < COUNTRIES_NUMBER; i++)
for(j = 0; j < (ARRAYS_LENGTH - 1); j++) {
- country_codes[i][j] = '\0';
+ country_codes[i][j] = 'a';
country_codes[i][ARRAYS_LENGTH - 1] = '\n';
}
diff --git a/main.c b/main.c
@@ -37,13 +37,9 @@ int main(int argc, char * argv[])
// Las siguientes variables son para guardar los nombres de los archivos de
// entrada y salida luego de validar los argumentos
-// char src[MAX_NAME_LENGTH], dest[MAX_NAME_LENGTH];
char src[MAX_NAME_LENGTH];
char dest[MAX_NAME_LENGTH];
- //src = (char *)malloc(MAX_NAME_LENGTH);
- //dest = (char *)malloc(MAX_NAME_LENGTH);
-
FILE *fpi, *fpo;
uint country, date, infected;
@@ -53,7 +49,6 @@ int main(int argc, char * argv[])
infected_monthly = 0;
// Arreglo de arreglos de caracteres para guardar los codigos de los paises
-// char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
char **country_codes = (char **)malloc(COUNTRIES_NUMBER * sizeof(char *));
for (size_t i = 0; i < COUNTRIES_NUMBER; i++)
country_codes[i] = (char *)malloc(ARRAYS_LENGTH * sizeof(double));
@@ -65,6 +60,7 @@ 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'
if((st = load_country_codes(country_codes)) != OK) {
@@ -94,7 +90,7 @@ int main(int argc, char * argv[])
size_t line;
for(line = 0; (st = read_file(fpi, &country, &date, &infected)) == OK; line++) {
if(line != 0) {
-// print_file(fpo, country_codes, &country, &date, &infected);
+ print_file(fpo, country_codes, &country, &date, &infected);
}
}
diff --git a/print_file.c b/print_file.c
@@ -5,7 +5,7 @@ const char formato_de_la_fecha[] = "%d %b %Y";
int prev_month, prev_country;
ulong infected_monthly;
-status_t print_file(FILE *dest, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH], uint *country, uint *date, uint *infected) {
+status_t print_file(FILE *dest, char **country_codes, uint *country, uint *date, uint *infected) {
int month;
char time_s[TIME_MAX_DIGITS];
@@ -44,7 +44,7 @@ status_t print_file(FILE *dest, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENG
}
-status_t fprintf_country(FILE *dest, size_t country_code, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
+status_t fprintf_country(FILE *dest, size_t country_code, char **country_codes)
{
if((country_codes == NULL) || (dest == NULL))
return ERROR_NULL_POINTER;
@@ -99,7 +99,7 @@ void fprintf_infected_monthly(FILE *dest)
char guion_medio[] = "-----------";
int length = snprintf( NULL, 0, "%lu", infected_monthly );
- char* str_infected_monthly = (char *)malloc( length + 1 * sizeof(char) );
+ char* str_infected_monthly = (char *)malloc(length + 1 * sizeof(char));
snprintf( str_infected_monthly, length + 1, "%lu", infected_monthly );
diff --git a/print_file.h b/print_file.h
@@ -3,11 +3,9 @@
#include "main.h"
-//extern const char formato_de_la_fecha[];
+status_t print_file(FILE *dest, char **country_codes, uint *country, uint *date, uint *infected);
-status_t print_file(FILE *dest, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH], uint *country, uint *date, uint *infected);
-
-status_t fprintf_country(FILE *dest, size_t country_code, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]);
+status_t fprintf_country(FILE *dest, size_t country_code, char **country_codes);
status_t fprintf_date(FILE *dest, size_t date);
status_t fprintf_infected(FILE *dest, uint infected, char newline);