I'm new to Data Structure, and tried to make a program that reads data from a .txt to a struct pessoa, transfer it to a list, and then gets the desired struct back, but I keep getting this error: "error: dereferencing pointer to incomplete type".
#include <stdio.h>
#include <stdlib.h>
typedef struct pessoa{
int matr;
char *nome;
char *curso;
int semestre;
struct pessoa *prox;
}aluno;
int insere(aluno *i, int m, char *n, char *c, int s){
aluno *h = (aluno*)malloc(sizeof(aluno));
h->matr=m;
h->nome=n;
h->curso=c;
h->semestre=s;
h->prox=i;
i=h;
return 0;
}
int buscamatricula(aluno *i, int m){
char n;
char c;
int s;
while (i->prox != NULL){
if (m == i->matr)
{
printf("Nome: %s\nMatricula: %i\nCurso: %s Semestre: %i\n", n, m, c, s);
break;
}
}
puts("Erro: nao foi possivel encontrar o aluno");
return 0;
}
main()
{
int x=0, a, b;
char e[50], f[50];
struct aluno *inic;
FILE *arq;
arq = fopen("turma.txt", "r");
if (arq == NULL)
puts("Deu ruim");
else
{
while (fscanf(arq, "%i %s %s %i", &a, e[50], f[50], &b) != EOF)
{
insere(*inic, a, e, f, b); //error here
}
fclose(arq);
}
while (x != -255)
{
printf("Que matricula vc deseja pesquisar? Para sair, digite \"-255\"\n");
scanf("%i", &x);
if (x == -255)
break;
buscamatricula(*inic, a); //also an error here
}
free(inic);
return 0;
}
I'm using Code::Blocks. What is wrong with my code?