读书人

建立一个空链表然后再输入数据输出

发布时间: 2013-08-09 15:16:24 作者: rapoo

建立一个空链表,然后再输入数据,输出时,为什么第一个数据为0?

struct client_msg
{
char name[20];
char *clientip;
int fdnumber;
int portnumber;
struct client_msg *next;
};

struct client_msg *list_create()
{
struct client_msg *lhead;
lhead=(struct client_msg *)malloc(sizeof(struct client_msg));
lhead->next=NULL;

return lhead;
}

void list_save(struct client_msg *head,char name[20],int ifdnumber,int iportnumber)
{
struct client_msg *ihead,*inew;
ihead=head;
inew=(struct client_msg *)malloc(sizeof(struct client_msg));
strcpy(inew->name,name);
inew->fdnumber=ifdnumber;
inew->portnumber=iportnumber;
inew->next=NULL;
if(NULL==head)
{
ihead=inew;
}else{
while(ihead->next!=NULL)ihead=ihead->next;
ihead->next=inew;
}
}
void list_print(struct client_msg *head)
{
struct client_msg *phead;
phead=head;

if(NULL==head)
{
printf("链表为空!\n");
}else{
printf("\n\n目前服务器在线人数:%d",n);
printf("\n-----------------------------\n");
printf("\t\t昵称:\t\t端口:\t\t套接字:\n");
while(phead!=NULL)
{
printf("\t\t%s\t\t%d\t\t%d\n",
phead->name,phead->portnumber,phead->fdnumber);
phead=phead->next;
}
printf("\n-----------------------------\n");


}
}



我做的问题可能出在建立空链表上,但是无论我怎么试都不行啊! 链表 C,linux
[解决办法]
没有看到main函数,不知道具体情况
不过有可能是你链表带了头结点.输出的时候,第一个输出头结点.

读书人网 >C语言

热点推荐