9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 608fda620724f8cea962aea240a0230a327e07b7
parent d5e4a472e68c0b102c92927864280b2337c6c5e1
Author: klewer-martin <mk@inspiron.localdomain>
Date:   Mon, 25 Jan 2021 16:50:06 -0300

Updated and added files;

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