Can someone help me with the Pointers in function, in this code?

Asked

Viewed 57 times

0

Guys, after implementing the function deleting my code no longer works, could someone help me? without deleting function is working, what is wrong with it?

//biblioteca

#include<stdlib.h>
#include<stdio.h>

// Constantes 

#define MAX 2

//Estruturas

typedef struct aluno{
    int matricula;
    int cpf;
}aluno;



//funçoes
void inserir(int qtd_aluno , aluno *a){

    for( int i = 0 ; i < qtd_aluno ; i++){
        printf("1 - Inserir Aluno>>\n");
        printf("Digite a matricula: \n");
            scanf("%d", &a[i].matricula);
        printf("Digite o cpf: \n");
            scanf("%d", &a[i].cpf);

    }   
}

void buscar(aluno *a){
    int i;
    int cpfb;
    printf("2 - Buscar Aluno\n\n");

    printf("Digite o cpf do aluno a ser buscado: ");
        scanf("%d",&cpfb);
    for (int i = 0; i < MAX; i++)
        if (cpfb == a[i].cpf)
            printf("\nAluno encontrado!\n Aluno numero: %d\n Matricula: %d", i+1,a[i].matricula);

        else
            printf("Aluno nao econtrado!"); 
}



void relatorio(aluno *a){

    printf("4 - Gerar Relatorio...\n\n");
    for (int i = 0; i < MAX; i++){
        printf("Matricula do Aluno: %d\n", a[i].matricula);
        printf("cpf do Aluno: %d\n", a[i].cpf);
    }

}


void deletar(int qtd_aluno, aluno *a){
    int matcomp, i=0;

    printf("\n 3 - Deletar Aluno \n");
    relatorio(a);
    printf("Digite a matricula do aluno que deseja deletar.");
    scanf("%d",&matcomp);
    for(i=0; i<qtd_aluno;i++){
        if(matcomp == a[i].matricula){
            &a[i].matricula = 0;
            &a[i].cpf= 0;
        }

    }


}


//funçao main
int main ()
{

    int op ;
    aluno a[MAX];

    do {

    printf(" ------------- Cadastro de Alunos -------------\n\n");
    printf(" --------- Insira a opcao de cadastro ----------\n\n");
    printf("| 1 - Inserir Aluno                            |\n");
    printf("| 2 - Buscar Aluno                             |\n");
    printf("| 3 - Deletar Aluno                            |\n");
    printf("| 4 - Gerar um Relatorio                       |\n");
    printf("| 5 - Sair                                     |\n");
    printf(" -----------------------------------------------\n\n"); 
    scanf("%d",&op);

        switch(op){
            case 1 : 
                system("cls");
                inserir(MAX , a);
                break;
            case 2 : 
                system("cls");
                buscar(a);
                break;
            case 3 : 
                system("cls");
                deletar(a);
                break;
            case 4 : 
                system("cls");
                relatorio(a);
                break;
            case 5 : 
                system("cls");
                printf("5 - Saindo...");
                break;
            default : 
                system("cls");
                printf("Opcao Invalida - Faça novamente");
                break;
        } 
    }while (op != 5);
return 0;
}
  • The problem has been solved

  • tries to take out the & of &a[i]..

1 answer

2

Taking a quick look, you created the function void deletar(int qtd_aluno, aluno *a) with two parameters and in function call deletar(a); used only one parameter. This is only possible if you implement optional parameters.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.