How to find something specific inside a text file

1
Hello, I have to check the grades of a particular student and if his average is greater than 5 show the name so I do not have the idea of how to do this ... nor to ask how he does it so sorry if I was not clear

struct ALUNOS{
    char nome[50];
    float nota1, nota2;
}aluno;

void cadastra(){
    FILE *arquivo;
    ALUNOS aluno;
    char resp, numstr[40];

    arquivo = fopen("alunoscad.txt","wt");
    if (arquivo == NULL){
        printf("\n Erro abertura!");
        exit(1);
    }
    do{
        printf("\n Nome: ");
        gets(aluno.nome);
        printf("\n Nota 1: ");
        gets(numstr);
        aluno.nota1 = atof(numstr);
        printf("\n Nota 2: ");
        gets(numstr);
        aluno.nota2 = atof(numstr);



            fprintf(arquivo,"%s",aluno.nome);
            fprintf(arquivo,"\n%.2f",aluno.nota1);
            fprintf(arquivo,"\n%.2f\n",aluno.nota2);


        printf("\n Deseja cadastrar mais? \n");
                do {
            resp = toupper(getch());
        } while (resp != 'S' && resp != 'N');

    }while(resp=='S');


    fclose(arquivo);


}

void mostra (){
    FILE *arquivo;
    ALUNOS aluno;

    char ch;
    int achou = 0;
    if ((arquivo = fopen("alunoscad.txt", "rt")) == NULL){
        printf("\n Erro abertura");
        exit(1);
    }
    while ((ch = getc(arquivo)) !=EOF){


        fgets()
    }
        fclose (arquivo);

}

int main(){
    cadastra();
    mostra();
}

This is all my code

    
asked by anonymous 05.11.2015 / 17:09

1 answer

0

I get something like this but it does not le the file and without the struct

void mostra (){
FILE *arquivo;
ALUNOS aluno[100];
int aux;
char ch;
int achou = 0;
if ((arquivo = fopen("alunoscad.txt", "rt")) == NULL){
    printf("\n Erro abertura");
    exit(1);
}
for(int i=0;i<b;i++){

    aux = 0;
    aux = (aluno[i].nota1+aluno[i].nota2)/2;
    printf("Media: \n%d",aux);
    if(aux>=5){

        printf("Aluno: \n%s",aluno[i].nome);
            }
    }
}
    
05.11.2015 / 18:16