How to manage a triple pointer in C++

Viewed 49

I tried to solve a problem with triple pointer using dynamic memory but I had a problem. I tried to create a triple pointer with 2 static dimensions to try to count the exact number of character strings that I would need. The reason of using that static pointer is to assign the correct number of subjects to the students that I will show soon. In this problem I had 2 txt docs. First I had a number of students and their IDs

Then I had a number of registers with many subjects that I need to add to the students according their IDs or codes

Code:

void leerCursos(int *codigos,char ***&cursos){
    ifstream arch;
    abrirArchivosLectura("Cursos.csv",arch);
    int auxCod,nota,pos,aa,i;
    char *buffCurso[100][20],*codCur,c;
    for(i=0;codigos[i];i++);
    int numDat[i]={};
    while(1){
        cout<<"Llegue";
        arch>>auxCod;
        if(arch.eof())break;
        arch.get();
        codCur=leerCadena(arch,',');
        arch>>nota>>c;
        arch>>aa;
        aa*=1000;
        if(nota>=11&&auxCod>=aa){
            pos=buscarEntero(codigos,auxCod);
            agregaCurso(buffCurso[pos],codCur,numDat[pos]);
        } 
        limpiaLinea(arch);
    }
    cout<<"uwu";
    for(i=0;codigos[i];i++)strcpy(buffCurso[i][numDat[i]],"X");
}
void agregaCurso(char **cursos,char *codigo,int &numDat){
    strcpy(cursos[numDat],codigo);
    numDat++;
}
int buscarEntero(int *arr,int buscar){
    for(int i=0;arr[i];i++)if(arr[i]==buscar)return i;
    cout<<"ERROR, no se encontro el entero: ",buscar;
    exit(1);
}
char * leerCadena(ifstream &arch,char c){
    char buffer[100],*cadena;
    int numDat=0;
    arch.getline(buffer,100,c);
    cadena = new char [strlen(buffer)+1];
    strcpy(cadena,buffer);
    return cadena;
}
0 Answers
Related