How to manage 16208 registers from a txt file to sort them?

Viewed 40

I'm a beginner in programming & now I'm trying to sort and search data from a .txt file with C++, the file has 16208 lines, and each line is a register so, Idk how could I manage an array or ony other data structure, first to sort and then to search data of the file, how could I do It? implement an a dynamic array with resize or something like that?

This is from CArchivo.h

#pragma once
#include <bits/stdc++.h>

class CArchivo{

    public:

        errno_t error; // Opcional
        FILE* archivo;
        char cadena[75];
        //char* resultadoString;

        void abrirArchivo(const char nombreArchivo[15]);
        void cerrarArchivo();
        void imprimirArchivo();
        void ordenarRegistros();
        void guardarRegistros();
        void buscarRegistros(std::string fechaInicial, std::string fechaFinal );
        int contarRegistros();

        CArchivo();
        ~CArchivo();
};

This is from CArchivo.cpp

#include "CArchivo.h"


void CArchivo::abrirArchivo(const char nombreArchivo[15]) {

    error = fopen_s(&archivo, nombreArchivo, "r");
    error == 0 ? std::cout << "The file has open\n" : std::cout << "Failed to open the file\n";

}
void CArchivo::cerrarArchivo() {

    error = fclose(archivo);
    error == 0 ? std::cout << "\nThe file is closed\n" : std::cout << "\nThe file isn't closed\n";
}

void CArchivo::imprimirArchivo() {

    if (error != 0)
    {
        printf("Error en la apertura/creacion del archivo");
    }
    else {

        do {
            fgets(cadena, 75, archivo);
            printf("%s", cadena);
        } while (!feof(archivo));

    }

}

void CArchivo::ordenarRegistros() {

    std::string stringResult = "";
    int sizeArr = 0;
    //const int contArr = contarRegistros();

    //std::string* dataArr = new std::string[contArr];

    do
    {
        fgets(cadena, 75, archivo);
        printf(cadena);
        //std::cout << stringResult;
        //dataArr[sizeArr] = stringResult;
        //sizeArr += 1;
    } while (!feof(archivo));

    

    //std::cout << dataArr[0];

    //delete[] dataArr;

}

void CArchivo::guardarRegistros() {

}

void CArchivo::buscarRegistros(std::string fechaInicial, std::string fechaFinal) {

}

int CArchivo::contarRegistros() {

    int sizeArr = 0;

    //Count the number of registers
    if (error != 0)
    {
        printf("Error en la apertura/creacion del archivo");
    }
    else {
        do {
            fgets(cadena, 75, archivo);
            sizeArr++;
        } while (!feof(archivo));
    }

    return sizeArr;
}

CArchivo::CArchivo() {
    
    error = NULL;
    //resultadoString = NULL;
    cadena[74] = NULL;
    archivo = NULL;

}

CArchivo::~CArchivo() {}```
0 Answers
Related