Why does this error occur? - invalid application of 'sizeof' to incomplete type

2

When I try to compile (gcc test.c) it generates the following error:

Thecode:

#include<stdio.h>#include<stdlib.h>#include<string.h>typedefstructalunoAluno;intmain(){Aluno*a;a=malloc(sizeof(Aluno));//InseredadosnoscamposdotipoAlunoa->matricula=123;strcpy(a->nome,"victhor");
    strcpy(a->curso,"computação");

    int *matricula;
    char *nome, *curso;

    //Copia os dados de Aluno para as variáveis
    matricula=(int*)&(a->matricula);
    nome=(char*)&a->nome;
    curso=(char*)&a->curso;

    acessa(a,matricula, nome, curso);
    printf("Matrícula: %d\n",*matricula);
    printf("Nome: %s\n", nome);
    printf("Curso: %s\n", curso);
    return 0;
}

typedef struct aluno{
    int matricula;
    char nome[50];
    char curso[20];
}Aluno;
    
asked by anonymous 04.11.2016 / 18:42

1 answer

2

Put the following code before the function main .

typedef struct aluno{
    int matricula;
    char nome[50];
    char curso[20];
}Aluno;

Reason: it is doing malloc before loading the data structure itself, so it is giving error.

    
04.11.2016 / 19:20