I encountered a problem about pointer and structure.
#include<stdlib.h>
#include<stdio.h>
Define two structure, sub term and major term.
typedef struct{
int sub_id;
int sub_data;
struct sub_term *next_term;
}sub_term;
typedef struct{
char name[10];
struct sub_term *init_term;
struct sub_term *current_term;
}major_term;
I want to create a major term that contains sub term.
int main(void){
major_term *Test_1;
Test_1 = (major_term *)malloc(sizeof(major_term));
Test_1->init_term = (sub_term *)malloc(sizeof(sub_term));
Test_1->current_term = Test_1->init_term;
printf("Sub term 1 id : ");
However, compiler notices me that "[Error] dereferencing pointer to incomplete type" in this line.
scanf("%d",&Test_1->current_term->sub_id);
I am new to C language and not sure the reason. Thank you for your recommend that makes my code better !
printf("Sub term 1 id : ",Test_1->current_term->sub_id);
printf("Sub term 1 data: ");
scanf("%d",&Test_1->current_term->sub_data);
printf("Sub term 1 data : ",Test_1->current_term->sub_data);
return 0;
}