- 论坛徽章:
- 0
|
creatoutlist为建立含一个节点的链表的函数。经gcc编译,程序执行时
输出
malloc of 24 bytes success!
saddrip=210.76.120.6,length=32342
segmentation fault(core dumped)
在strcpy(s->;saddr,saddrip); 开始出现故障。
#define LEN sizeof(linkoutlist)
typedef struct outnode
{
char saddr[16];
unsigned long length;
struct outnode * next;
}linkoutlist;
void *emalloc(unsigned int n)
{
void *p;
p = malloc(n);
if(p=NULL)
printf("malloc of %u bytes failed:\n",n);
else
printf("malloc of %u bytes success!\n",n);
return p;
}
linkoutlist *creatoutlist(char *saddrip,unsigned long length)
{
linkoutlist * head,* s;
// head = (linkoutlist *) emalloc(LEN);
head = NULL; /* outlist链表开始为空 */
s = (linkoutlist *) emalloc(LEN);
// s->;saddr = saddrip;
printf("saddrip=%s,length=%lu.\n",saddrip,length);
strcpy(s->;saddr,saddrip); //出现故障???
s->;length = length; //出现故障????
printf("333333\n" ;
s->;next = head;
head = s;
return head;
}
请教:
1。 malloc of 24 bytes success! 中24是怎么得出来的?
2。为何strcpy(s->;saddr,saddrip); //出现故障???
我该如何做,才能把saddrip=210。76。120。6信息存放到链表中? |
|