#include "tiledef.hpp" tile_t* ParseTileData(std::string tile) { tile_t* t; size_t blocksize = 512; char* buf = new char[blocksize]; if(tile.size() == 0) { std::printf("[ERROR]: Tile data corrupt or empty!\n"); std::exit(1); } // Parsing the tile data while(std::fgets(buf, sizeof buf, stdin)) { uint32_t id = std::strtol(buf, NULL, 0); t->id = id; std::printf("[DATA]: \nTileID: \t%d\n", id); } // Check if buffer still contains some data delete buf; return t; } // Opens the tile table, reads it line-by-line, // Removes newlines from read string and saves it to the string table; std::vector LoadTiles() { std::vector tileids; std::ifstream file; std::string line; char c = '\0'; size_t len = 0; size_t lines = 0; size_t read = 0; // Open the file as text file.open("tileids.txt", std::ios::in); // Check whether the file exists, is corrupt or empty if(file.bad()) { std::printf("[ERROR]: TileID table corrupt or empty!\n"); file.close(); std::exit(1); } else { // Count the number of lines in the file lines = CountLines(file); std::printf("[DEBUG]: Lines: [%zu]\n", lines); // Reset the position of the file file.seekg(std::ios::beg); // Read the file line by line while(std::getline(file, line)) { // Remove any unnecessary newlines if(line[line.size()-1] == '\n') { line[line.size()-1] = '\0'; } // Print the content and the length std::printf("[DATA]: \n\t[%s]", line); std::printf("\t[LENGTH]: [%zu]\n", read); // Save the content of the line into a string array tileids.push_back(line); std::printf("\t[TILEID]: \t[%s]\n", tileids.at(read++)); } // Close the file file.close(); } return tileids; } int main() { std::printf("[DEBUG]: Initialized!\n\n"); std::vector tmp; tmp = LoadTiles(); std::printf("\n[TILEID LIST]: \n"); for(auto &i: tmp) { std::printf("\t[%s]\n", i); } std::printf("\n"); return 0; } /* The output: * [DEBUG]: Initialized!  * [DEBUG]: Lines: [2]  * [TILEID LIST]: *  * Process returned 0 (0x0) execution time : 0.010 s  * Press any key to continue. */