9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 3ff41d4e8a44c9cd2b5ce55b994c594810de7ce3
parent db378988e8463bb27f1df408294abdd10e0fea4d
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Tue,  2 Feb 2021 18:54:28 -0300

Updated Makefile and Source code;

Diffstat:
MMakefile | 2+-
Mload_country_codes.c | 19++++++++-----------
Dmain | 0
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/Makefile b/Makefile
@@ -16,7 +16,7 @@ data.o: main.c main.h
     $(CC) -c data.c
 
 load_country_codes.o: load_country_codes.h main.h
-    $(CC) -c load_country_codes.c main.o
+    $(CC) -c load_country_codes.c 
 
 clean:
     rm -f *.o
diff --git a/load_country_codes.c b/load_country_codes.c
@@ -2,12 +2,12 @@
 #include "macros.h"
 #include "load_country_codes.h"
 
-status_t clean (char *buffer)
+status_t clean (char *buffer, size_t size)
 {
     size_t i;
     i = 0;
-    while(buffer[i] != '\0') {
-        buffer[i] = ' ';
+    while(i < size) {
+        buffer[i] = '\0';
         i++;
     }
     return OK;
@@ -32,8 +32,8 @@ status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
     FILE *fp;
 
     char *buff;
-    char buff_2[20];
-    buff_2[19] = '\0';
+    char buff_2[INITIAL_SIZE];
+    buff_2[INITIAL_SIZE] = '\0';
 
     int country_code;
     char country_name[INITIAL_SIZE];
@@ -49,18 +49,16 @@ status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
 
 
     while(fgets(buff, INITIAL_SIZE, fp) != NULL) {
-//        printf("%s", buff);
-
+        clean(country_name, INITIAL_SIZE);
         for(i = 0, j = 0, part = CODE; (*(buff + i)) != '\0'; i++) {
-
+//            putchar((*(buff + i)));
             if((*(buff + i)) == ',') {
                 country_code = atoi(buff_2);
-                clean(buff_2);
+                clean(buff_2, INITIAL_SIZE);
 //                printf("%d\n", country_code);
                 part = NAME;
                 i++;
             } else if (*(buff + i + 1) == '\n') {
-//                clean(country_name);
                 part = CODE;
                 j = 0;
             }
@@ -71,7 +69,6 @@ status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
                 case NAME: country_name[j] = *(buff + i); j++; break;
             }
         }
-//        putchar(country_name[1]);
         printf("%s\n", country_name);
         strcpy(country_name, country_codes[country_code]);
     }
diff --git a/main b/main
Binary files differ.