How do I save issues in an array of pointers

1

Good evening

I come here to try to dispel a programming problem that occurs to me. In this solution, I have a file with several questions, each question being a question of one of the following 3 themes:

  • GEO - Geography
  • MAT - Mathematics
  • HIS - History
  • If the user in program execution chooses, answer geography questions, then a method will be invoked that selects only geography questions. This method has among other code the following:

    while (fgets(pergunta, 150, f) != NULL) // ler ficheiro linha a linha
        {
            sscanf(pergunta,"%ld", &elapsed_seconds); // ler cada poergunta do ficheiro
            length = sizeof(pergunta) - 4; // pegar no tamanho dos primeiros 4 caracteres
    
            for (int j = 0; j < length; j++)
            {
                if (pergunta[j] == 'G' && pergunta[j + 1] == 'E' && pergunta[j + 2] == 'O') // se a pergunta é de GEO
                {
                    for (int i = 0; i <= sizeof(questoes); i++)
                    {
    
                        //Problema 
                        if(!questoes[i]) // se encontrar posicao vazia
                            questoes[i] = pergunta; // guarda pergunta no apontador
    
                        if (i == sizeof(questoes))
                        {
                            resultadoRetomado = 1;
                            break;
                        }
                    }
                }
                else if (pergunta[j] != 'G' && pergunta[j + 1] != 'E' && pergunta[j + 2] != 'O')
                {
                    pergunta[j] = '
    while (fgets(pergunta, 150, f) != NULL) // ler ficheiro linha a linha
        {
            sscanf(pergunta,"%ld", &elapsed_seconds); // ler cada poergunta do ficheiro
            length = sizeof(pergunta) - 4; // pegar no tamanho dos primeiros 4 caracteres
    
            for (int j = 0; j < length; j++)
            {
                if (pergunta[j] == 'G' && pergunta[j + 1] == 'E' && pergunta[j + 2] == 'O') // se a pergunta é de GEO
                {
                    for (int i = 0; i <= sizeof(questoes); i++)
                    {
    
                        //Problema 
                        if(!questoes[i]) // se encontrar posicao vazia
                            questoes[i] = pergunta; // guarda pergunta no apontador
    
                        if (i == sizeof(questoes))
                        {
                            resultadoRetomado = 1;
                            break;
                        }
                    }
                }
                else if (pergunta[j] != 'G' && pergunta[j + 1] != 'E' && pergunta[j + 2] != 'O')
                {
                    pergunta[j] = '%pre%';
                }
            }
    
            }
    
    '; } } }

    Problem: If a geography question is found, the char* questoes[50] pointer, passed as a parameter to the method, will be traversed and the first question found will be stored. I intend to and have tried to change this algorithm to check if there is any empty position in the pointer set.

    Purpose: I want to keep the question char * quests [50] a set of 50 questions. How can I change this code so I can browse through the file and save the 50 questions?

    Thanks in advance,

        
    asked by anonymous 12.11.2017 / 01:28

    0 answers