If there is no type defined for the struct
it is necessary to inform explicitly the struct
, basically like this struct aluno a
. In addition, the passage of struct
can be done by reference or by value. See examples below.
Passing a struct
for function by value:
struct aluno lerAlunoValor(struct aluno a)
{
printf("Digite o numero matricula (Por Valor): ");
scanf("%i", &a.matricula);
return a;
}
Passing a struct
for function by reference:
void lerAlunoRef(struct aluno *a)
{
printf("Digite o numero matricula (Por referencia): ");
scanf("%i", &a->matricula);
}
Note that a new value is returned in the passage struct
, already in the passage by reference to struct
is modified within the function scope lerAlunoRef()
.
Follow the full example:
#include <stdio.h>
struct aluno
{
int matricula;
};
struct aluno lerAlunoValor(struct aluno a)
{
printf("Digite o numero matricula (Por Valor): ");
scanf("%i", &a.matricula);
return a;
}
void lerAlunoRef(struct aluno *a)
{
printf("Digite o numero matricula (Por referencia): ");
scanf("%i", &a->matricula);
}
int main(void)
{
struct aluno a, b;
a = lerAlunoValor(a);
lerAlunoRef(&b);
printf("\n\nPor valor (Matricula): %i\n", a.matricula);
printf("\n\nPor referencia (Matricula): %i\n", b.matricula);
return 0;
}
Entree:
Enter the number plate (Per Value): 122
Enter the number plate (By reference): 22
Exit:
By value (Registration): 122
By reference (Matricula): 22
See working on repl it..
You can consult more here.
What type of function
tabela
? That part was missing. By the look of the code it would be typevoid
– Isac
How are you calling the function
tabela()
?– gato