c - structure within structure declared in a file not able to access inner structure -
i have created file msgbuf.h follows:
//msgbuf.h typedef struct msgbuf1 { long mtype; m1 *m; } message_buf; typedef struct msgclient { int msglen; int msgtype; char cp[100]; }m1;
and program check.c. below prog giving error there no m1. why so? mistake doing? think contents of file "msgbuf.h" should copied in prog check.c , program should run fine. please let me know this.
//check.c #include<stdio.h> #include<string.h> #include<stdlib.h> #include"msgbuf.h" int main() { message_buf *sbuf; sbuf=malloc(sizeof(sbuf)); sbuf->m=malloc(sizeof(m1)); sbuf->m->msglen=10; printf("\n%d",sbuf->m->msglen); printf("\n %d",sizeof(sbuf->m)); return 0; }
thanks :)
simple, declare m1
before message_buf
; .
typedef struct msgclient { int msglen; int msgtype; char cp[100]; }m1; typedef struct msgbuf1 { long mtype; m1 *m; } message_buf;
and read keltar's comments below question too.
Comments
Post a Comment