diff --git a/Aufg4/CrimeStats.cpp b/Aufg4/CrimeStats.cpp index 913c452..220d5e3 100644 --- a/Aufg4/CrimeStats.cpp +++ b/Aufg4/CrimeStats.cpp @@ -15,17 +15,6 @@ // ucr_ncic_code, // latitude, // longitude, -typedef struct CRIME{ -std::string cdatetime; -std::string address; -std::string district; -std::string beat; -std::string grid; -std::string crimedescription; -std::string ucr_ncic_code; -std::string latitude; -std::string longitude; -} Crime; void split(const std::string& s, char c,std::vector& v) { std::string::size_type i = 0; @@ -41,9 +30,9 @@ void split(const std::string& s, char c,std::vector& v) { } } -std::string readFile(std::string &fileName) { +std::string readFile(std::string &fileName, std::vector &allCrimes) { std::string content; - std::ifstream infile(fileName); + std::ifstream infile; infile.open(fileName); if (!infile.is_open()) { @@ -54,8 +43,14 @@ std::string readFile(std::string &fileName) { std::string line; while (std::getline(infile, line)) { - std::cout << line << std::endl; content += line; + + std::vector actualLines; + split(line, '\r', actualLines); + + for (auto actual_line: actualLines) { + allCrimes.push_back(stringToCrime(actual_line)); + } } return content; } @@ -66,7 +61,7 @@ Crime* stringToCrime(std::string &input) { Crime* thisCrime = new Crime; for (int i = 0; i < tokens.size(); i++) { - switch (i) { + switch (i%tokens.size()) { case 0: thisCrime->cdatetime = tokens[0]; break; @@ -93,17 +88,21 @@ Crime* stringToCrime(std::string &input) { break; case 8: thisCrime->longitude = tokens[8]; + break; default: + std::cout << "I am the Default case " << tokens.size() << std::endl; } } return thisCrime; } void Aufg4Main() { - // std::string fileName = "../Aufg4/IO-Files/SacramentocrimeJanuary2006.csv"; - std::string fileName = "../Aufg4/IO-Files/debugging.test"; - std::string content = readFile(fileName); - std::vector vector; + std::string fileName = "../Aufg4/IO-Files/SacramentocrimeJanuary2006.csv"; + std::vector allCrimes; + std::string content = readFile(fileName, allCrimes); + // std::cout << content << std::endl << "EndOfFile" << std::endl; + + std::cout << allCrimes.at(2)->crimedescription << std::endl; } \ No newline at end of file diff --git a/Aufg4/CrimeStats.h b/Aufg4/CrimeStats.h index f354c29..69189dc 100644 --- a/Aufg4/CrimeStats.h +++ b/Aufg4/CrimeStats.h @@ -3,11 +3,25 @@ #include #include +typedef struct CRIME{ + std::string cdatetime; + std::string address; + std::string district; + std::string beat; + std::string grid; + std::string crimedescription; + std::string ucr_ncic_code; + std::string latitude; + std::string longitude; +} Crime; + void split(const std::string& s, char c,std::vector& v); void Aufg4Main(); -std::string readFile(std::string &filename); +std::string readFile(std::string &filename, std::vector &allCrimes); + +Crime* stringToCrime(std::string &input); #endif //CRIMESTATS_H