- 论坛徽章:
- 0
|
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<stddef.h>
#define APPEND_STRUCT 2
typedef struct _msg
{
unsigned short len;
char chkode[3];
}msg;
typedef struct _msg_node
{
unsigned short msg_len;
char name[5];
msg msg_no[0];
}msg_node;
int main(int argc,char *argv[])
{
msg_node * p;
printf("\n");
printf("msg_node test!\n");
p=(msg_node*)malloc(sizeof(msg_node)+sizeof(msg));
//&(p->msg_no[0])=(msg *)malloc(APPEND_STRUCT*sizeof(msg));
memset(p->msg_no,0,sizeof(msg));
(*(p->msg_no)).len=2;
strcpy((*(p->msg_no)).chkode,"1");
printf("output some message!\n");
printf("len:%d chkode:%s\n",(*(p->msg_no)).len,(*(p->msg_no)).chkode);
free(p);
exit(0);
}
看了一些文章,照着别人的样子写了一个程序,为什么显示:
msg_node test!
Segmentation fault
请高人指点,谢谢
[ 本帖最后由 kejunlqp 于 2007-9-19 14:50 编辑 ] |
|