试下把
ptr->name[16]=name1;
改为:
strcpy(ptr->name, name1);
#include
#include
#include
#include
struct list
{
char name[16];
struct list *next;
};
typedef struct list node;
typedef node *link ;
main()
{
link ptr,head,chang;
char name1[16];
int end=0;
head=(link)malloc(sizeof(node));
ptr=head;
printf("please input name ==>\n");
while(1)
{
gets(name1);
end=strcmp(name1,"#")==0;
if(end)break;
strcpy(ptr->name,name1);
chang=(link)malloc(sizeof(node));
ptr->next=chang;
ptr=chang;
}
if(end)
ptr->next=NULL;
ptr=head;
while(ptr->next!=NULL)
{
printf("the name is==>%s\n",ptr->name);
ptr=ptr->next;
}
getch();
}
试下,在VC.NET下通过。