小
小唐
Unregistered / Unconfirmed
GUEST, unregistred user!
#include <stdio.h>
struct list
{
int bh;
char name[10];
struct list *next;
};
typedef struct list node;
typedef node *link;
link create_link(link head)
{
int number=1;
char nameitem[10];
int i;
link newde;
link pointer;
head=(link)malloc(sizeof(node));
if (head=NULL) putchar(7);
head->bh=number;
printf("/nPlease input string:");
scanf("%s",nameitem);
for (i=0;i<10;i++)
head->name=nameitem;
head->next=NULL;
pointer=head;
while (1)
{
number++;
newde=(link)malloc(sizeof(node));
newde->bh=number;
scanf("%s",nameitem);
if (nameitem[0]=='0')
break;
for (i=0;i<10;i++)
newde->name=nameitem;
newde->next=NULL;
pointer->next=newde;
pointer=newde;
}
return head;
}
void display_link(link head)
{
link pointer;
pointer=head;
while (pointer !=NULL)
{
printf("pointer->bh=%d/n",pointer->bh);
printf("pointer->name=%s/n",pointer->name);
pointer=pointer->next;
}
}
void free_link(link head)
{
link pointer;
while (head !=NULL)
{
pointer=head;
head=head->next;
free(pointer);
}
}
void main(void)
{
link ahead;
create_link(ahead);
display_link(ahead);
free_link(ahead);
}
当我输入完数据,按“0”再回车,按ALT+F5查看结果,
发现屏幕上head->name=的后面出现的是乱码,后面有句
英语提示,好象是说指针出了问题,我调试检查了很久,
都不知错在哪里,我和书上的程序核对了很多遍的。
请教各位了。
struct list
{
int bh;
char name[10];
struct list *next;
};
typedef struct list node;
typedef node *link;
link create_link(link head)
{
int number=1;
char nameitem[10];
int i;
link newde;
link pointer;
head=(link)malloc(sizeof(node));
if (head=NULL) putchar(7);
head->bh=number;
printf("/nPlease input string:");
scanf("%s",nameitem);
for (i=0;i<10;i++)
head->name=nameitem;
head->next=NULL;
pointer=head;
while (1)
{
number++;
newde=(link)malloc(sizeof(node));
newde->bh=number;
scanf("%s",nameitem);
if (nameitem[0]=='0')
break;
for (i=0;i<10;i++)
newde->name=nameitem;
newde->next=NULL;
pointer->next=newde;
pointer=newde;
}
return head;
}
void display_link(link head)
{
link pointer;
pointer=head;
while (pointer !=NULL)
{
printf("pointer->bh=%d/n",pointer->bh);
printf("pointer->name=%s/n",pointer->name);
pointer=pointer->next;
}
}
void free_link(link head)
{
link pointer;
while (head !=NULL)
{
pointer=head;
head=head->next;
free(pointer);
}
}
void main(void)
{
link ahead;
create_link(ahead);
display_link(ahead);
free_link(ahead);
}
当我输入完数据,按“0”再回车,按ALT+F5查看结果,
发现屏幕上head->name=的后面出现的是乱码,后面有句
英语提示,好象是说指针出了问题,我调试检查了很久,
都不知错在哪里,我和书上的程序核对了很多遍的。
请教各位了。