9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit db378988e8463bb27f1df408294abdd10e0fea4d
parent c5f711cbf206a5b42438333439d96600f1ce2b6c
Author: klewer-martin <mk@inspiron.localdomain>
Date:   Tue,  2 Feb 2021 17:17:17 -0300

Update on project01 source code;

Diffstat:
MMakefile | 22++++++++++++++--------
Marguments.c | 2+-
Marguments.h | 4+---
Mdata.c | 1+
Mdata.h | 2+-
Ainput.csv | 10++++++++++
Aiso3166-1_numbers_and_countries.csv | 22++++++++++++++++++++++
Aiso3166-1_numbers_and_countries_def.csv | 249+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mload_country_codes.c | 36+++++++++++++++++++++++++++++++-----
Mload_country_codes.h | 11+----------
Mmacros.h | 2+-
Amain | 0
Mmain.c | 21+++++++++++++++++++--
Mmain.h | 10++++++----
14 files changed, 357 insertions(+), 35 deletions(-)
diff --git a/Makefile b/Makefile
@@ -3,19 +3,25 @@ $(CC)=gcc
 all: make_main clean
 
 
-make_main: main.o arguments.o data.o
-    $(CC) main.o arguments.o data.o -o main 
+make_main: main.o arguments.o data.o load_country_codes.o
+    $(CC) main.o arguments.o data.o load_country_codes.o -o main 
 
-main.o: src/main.c include/main.h include/arguments.h include/macros.h
-    $(CC) -c src/main.c
+main.o: main.c main.h arguments.h macros.h
+    $(CC) -c main.c
 
-arguments.o: src/arguments.c include/arguments.h include/macros.h
-    $(CC) -c src/arguments.c
+arguments.o: arguments.c arguments.h macros.h
+    $(CC) -c arguments.c
 
-data.o: src/main.c include/main.h
-    $(CC) -c src/data.c
+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
 
 clean:
     rm -f *.o
 
+run: 
+    ./main -in input.csv
+
 
diff --git a/arguments.c b/arguments.c
@@ -1,5 +1,5 @@
 #include "arguments.h"
-#include "macros.h"
+
 
 //    Checks if the arguments are right;
 status_t validate_arguments(int argc, char * argv[])
diff --git a/arguments.h b/arguments.h
@@ -1,7 +1,5 @@
 #include "main.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "macros.h"
 
 #ifndef ARGUMENTS_H
 #define ARGUMENTS_H
diff --git a/data.c b/data.c
@@ -1,4 +1,5 @@
 #include "main.h"
+#include "macros.h"
 
 void print_error(status_t error)
 {
diff --git a/data.h b/data.h
@@ -1,5 +1,5 @@
 #include <stdlib.h>
-#include "../include/main.h"
+#include "main.h"
 
 #ifndef DATA_H
 #define DATA_H
diff --git a/input.csv b/input.csv
@@ -0,0 +1,10 @@
+PAIS, FECHA, INFECTADOS
+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 
diff --git a/iso3166-1_numbers_and_countries.csv b/iso3166-1_numbers_and_countries.csv
@@ -0,0 +1,22 @@
+4,Afghanistan
+248,Aland Islands
+8,Albania
+12,Algeria
+16,American Samoa
+20,Andorra
+24,Angola
+660,Anguilla
+10,Antarctica
+28,Antigua and Barbuda
+32,Argentina
+51,Armenia
+533,Aruba
+36,Australia
+40,Austria
+31,Azerbaijan
+44,Bahamas
+48,Bahrain
+50,Bangladesh
+52,Barbados
+112,Belarus
+56,Belgium
diff --git a/iso3166-1_numbers_and_countries_def.csv b/iso3166-1_numbers_and_countries_def.csv
@@ -0,0 +1,249 @@
+4,Afghanistan
+248,Åland Islands
+8,Albania
+12,Algeria
+16,American Samoa
+20,Andorra
+24,Angola
+660,Anguilla
+10,Antarctica
+28,Antigua and Barbuda
+32,Argentina
+51,Armenia
+533,Aruba
+36,Australia
+40,Austria
+31,Azerbaijan
+44,Bahamas
+48,Bahrain
+50,Bangladesh
+52,Barbados
+112,Belarus
+56,Belgium
+84,Belize
+204,Benin
+60,Bermuda
+64,Bhutan
+68,Bolivia (Plurinational State of)
+535,"Bonaire, Sint Eustatius and Saba"
+70,Bosnia and Herzegovina
+72,Botswana
+74,Bouvet Island
+76,Brazil
+86,British Indian Ocean Territory
+96,Brunei Darussalam
+100,Bulgaria
+854,Burkina Faso
+108,Burundi
+132,Cabo Verde
+116,Cambodia
+120,Cameroon
+124,Canada
+136,Cayman Islands
+140,Central African Republic
+148,Chad
+152,Chile
+156,China
+162,Christmas Island
+166,Cocos (Keeling) Islands
+170,Colombia
+174,Comoros
+178,Congo
+180,"Congo, Democratic Republic of the"
+184,Cook Islands
+188,Costa Rica
+384,Côte d'Ivoire
+191,Croatia
+192,Cuba
+531,Curaçao
+196,Cyprus
+203,Czechia
+208,Denmark
+262,Djibouti
+212,Dominica
+214,Dominican Republic
+218,Ecuador
+818,Egypt
+222,El Salvador
+226,Equatorial Guinea
+232,Eritrea
+233,Estonia
+748,Eswatini
+231,Ethiopia
+238,Falkland Islands (Malvinas)
+234,Faroe Islands
+242,Fiji
+246,Finland
+250,France
+254,French Guiana
+258,French Polynesia
+260,French Southern Territories
+266,Gabon
+270,Gambia
+268,Georgia
+276,Germany
+288,Ghana
+292,Gibraltar
+300,Greece
+304,Greenland
+308,Grenada
+312,Guadeloupe
+316,Guam
+320,Guatemala
+831,Guernsey
+324,Guinea
+624,Guinea-Bissau
+328,Guyana
+332,Haiti
+334,Heard Island and McDonald Islands
+336,Holy See
+340,Honduras
+344,Hong Kong
+348,Hungary
+352,Iceland
+356,India
+360,Indonesia
+364,Iran (Islamic Republic of)
+368,Iraq
+372,Ireland
+833,Isle of Man
+376,Israel
+380,Italy
+388,Jamaica
+392,Japan
+832,Jersey
+400,Jordan
+398,Kazakhstan
+404,Kenya
+296,Kiribati
+408,Korea (Democratic People's Republic of)
+410,"Korea, Republic of"
+414,Kuwait
+417,Kyrgyzstan
+418,Lao People's Democratic Republic
+428,Latvia
+422,Lebanon
+426,Lesotho
+430,Liberia
+434,Libya
+438,Liechtenstein
+440,Lithuania
+442,Luxembourg
+446,Macao
+450,Madagascar
+454,Malawi
+458,Malaysia
+462,Maldives
+466,Mali
+470,Malta
+584,Marshall Islands
+474,Martinique
+478,Mauritania
+480,Mauritius
+175,Mayotte
+484,Mexico
+583,Micronesia (Federated States of)
+498,"Moldova, Republic of"
+492,Monaco
+496,Mongolia
+499,Montenegro
+500,Montserrat
+504,Morocco
+508,Mozambique
+104,Myanmar
+516,Namibia
+520,Nauru
+524,Nepal
+528,Netherlands
+540,New Caledonia
+554,New Zealand
+558,Nicaragua
+562,Niger
+566,Nigeria
+570,Niue
+574,Norfolk Island
+807,North Macedonia
+580,Northern Mariana Islands
+578,Norway
+512,Oman
+586,Pakistan
+585,Palau
+275,"Palestine, State of"
+591,Panama
+598,Papua New Guinea
+600,Paraguay
+604,Peru
+608,Philippines
+612,Pitcairn
+616,Poland
+620,Portugal
+630,Puerto Rico
+634,Qatar
+638,Réunion
+642,Romania
+643,Russian Federation
+646,Rwanda
+652,Saint Barthélemy
+654,"Saint Helena, Ascension and Tristan da Cunha"
+659,Saint Kitts and Nevis
+662,Saint Lucia
+663,Saint Martin (French part)
+666,Saint Pierre and Miquelon
+670,Saint Vincent and the Grenadines
+882,Samoa
+674,San Marino
+678,Sao Tome and Principe
+682,Saudi Arabia
+686,Senegal
+688,Serbia
+690,Seychelles
+694,Sierra Leone
+702,Singapore
+534,Sint Maarten (Dutch part)
+703,Slovakia
+705,Slovenia
+90,Solomon Islands
+706,Somalia
+710,South Africa
+239,South Georgia and the South Sandwich Islands
+728,South Sudan
+724,Spain
+144,Sri Lanka
+729,Sudan
+740,Suriname
+744,Svalbard and Jan Mayen
+752,Sweden
+756,Switzerland
+760,Syrian Arab Republic
+158,"Taiwan, Province of China"
+762,Tajikistan
+834,"Tanzania, United Republic of"
+764,Thailand
+626,Timor-Leste
+768,Togo
+772,Tokelau
+776,Tonga
+780,Trinidad and Tobago
+788,Tunisia
+792,Turkey
+795,Turkmenistan
+796,Turks and Caicos Islands
+798,Tuvalu
+800,Uganda
+804,Ukraine
+784,United Arab Emirates
+826,United Kingdom of Great Britain and Northern Ireland
+840,United States of America
+581,United States Minor Outlying Islands
+858,Uruguay
+860,Uzbekistan
+548,Vanuatu
+862,Venezuela (Bolivarian Republic of)
+704,Viet Nam
+92,Virgin Islands (British)
+850,Virgin Islands (U.S.)
+876,Wallis and Futuna
+732,Western Sahara
+887,Yemen
+894,Zambia
+716,Zimbabwe
diff --git a/load_country_codes.c b/load_country_codes.c
@@ -1,6 +1,19 @@
 #include "main.h"
+#include "macros.h"
 #include "load_country_codes.h"
 
+status_t clean (char *buffer)
+{
+    size_t i;
+    i = 0;
+    while(buffer[i] != '\0') {
+        buffer[i] = ' ';
+        i++;
+    }
+    return OK;
+}
+
+
 status_t empty_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]) 
 {
     size_t i, j;
@@ -19,34 +32,47 @@ status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
     FILE *fp;
 
     char *buff;
-    char buff_2[10];
+    char buff_2[20];
+    buff_2[19] = '\0';
 
     int country_code;
     char country_name[INITIAL_SIZE];
+    country_name[INITIAL_SIZE - 1] = '\0';
 
     size_t i, j;
     part_t part;
         
     buff = malloc(INITIAL_SIZE);
     
-    
-    if((fp = fopen("iso3166-1_numbers_and_countries.csv", "r")) == NULL)
+    if((fp = fopen(COUNTRY_CODES_FILE_NAME, "r")) == NULL)
         return ERROR_NULL_POINTER;
 
+
     while(fgets(buff, INITIAL_SIZE, fp) != NULL) {
+//        printf("%s", buff);
+
         for(i = 0, j = 0, part = CODE; (*(buff + i)) != '\0'; i++) {
-            if((*(buff + i + 1)) == ',') {
+
+            if((*(buff + i)) == ',') {
                 country_code = atoi(buff_2);
+                clean(buff_2);
+//                printf("%d\n", country_code);
                 part = NAME;
+                i++;
+            } else if (*(buff + i + 1) == '\n') {
+//                clean(country_name);
+                part = CODE;
+                j = 0;
             }
 
-
             switch(part)
             {
                 case CODE: buff_2[i] = *(buff + i); break;
                 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/load_country_codes.h b/load_country_codes.h
@@ -1,21 +1,12 @@
 #ifndef LOAD_COUNTRY_CODES
 #define LOAD_COUNTRY_CODES
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "main.h"
 
-#define INITIAL_SIZE        65
 #define COUNTRIES_NUMBER    500
 #define ARRAYS_LENGTH        25
 
 typedef enum {
-    OK,
-    ERROR_NULL_POINTER,
-    ERROR_LOADING_COUNTRY_CODES
-} status_t;
-
-typedef enum {
     CODE,
     NAME
 } part_t;
diff --git a/macros.h b/macros.h
@@ -7,7 +7,7 @@
 #define SOURCE_ARGUMENT            "-in"
 #define DESTINATION_ARGUMENT    "-out"
 
-#define INITIAL_SIZE        100
+#define INITIAL_SIZE        1000
 
 #define MSG_ERROR_NULL_POINTER    "ERROR_NULL_POINTER\n"\
                                 "An unexpected error has occured during the execution\n"\
diff --git a/main b/main
Binary files differ.
diff --git a/main.c b/main.c
@@ -1,10 +1,18 @@
 #include "main.h"
 #include "arguments.h"
 #include "macros.h"
+#include "load_country_codes.h"
+
+#define CANTIDAD_DE_DATOS 3
 
 int main(int argc, char * argv[])
 {
     status_t st;
+    FILE *fpi;
+//        , *fpo;
+
+    char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
+
     if((st = validate_arguments(argc, argv)) != OK) {
         print_error(st);
         return st;
@@ -22,8 +30,17 @@ int main(int argc, char * argv[])
     }
 
 
+    if(load_country_codes(country_codes) != OK)
+        return ERROR_LOADING_COUNTRY_CODES;    
 
-    return OK;
-}
 
+    printf("Hello world! (after load_country_codes call)\n");
+    printf("the country number 32 of iso 3166 is: %s\n", country_codes[32]);
+
+    fpi = fopen(src, "r");
+//    fpo = fopen(dest, "w");
 
+    fclose(fpi);
+//    fclose(fpo);
+    return OK;
+}
diff --git a/main.h b/main.h
@@ -1,16 +1,18 @@
+#ifndef MAIN_H
+#define MAIN_H
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "macros.h"
 
-#ifndef MAIN_H
-#define MAIN_H
+#define COUNTRY_CODES_FILE_NAME "iso3166-1_numbers_and_countries.csv"
 
 typedef enum {
     OK,
     ERROR_INVOCATING_PROGRAM,
     ERROR_NULL_POINTER,
-    NOT_FOUND
+    NOT_FOUND,
+    ERROR_LOADING_COUNTRY_CODES
 } status_t;
 
 #endif