struct element
{
char name[20];
char pwd[8];
struct element* next;
};
struct element* newElement(char * name ,char * pwd)
{
struct element* p = (struct element*)malloc(sizeof(struct element));
memset(p,'/0',sizeof(struct element));
strcpy(p->name,name);
strcpy(p->pwd,pwd);
p->next=0;
return p;
}
int add(struct element * head,struct element* ele)
{
if(head == 0)
{
head=ele;
return 1;
}
while(head->next!=0)
{
head=head->next;
}
head->next=ele;
return 1;
}
struct element* search(struct element * head ,char * name)
{
if(head == 0) return 0;
while(head->next != 0)
{
printf("%d/n",head);
if(strcmp(head->name,name)==0) return head;
head= head->next;
}
return 0;
}
int main()
{
struct element* e1= newElement("meng","123456");
struct element* e2= newElement("song","123123");
struct element* e3= newElement("li","123321");
printf("%d,%d/n",add(e1,e2),add(e1,e3));
struct element* e4= search(e1,"song");
printf("song pwd is :%s/n",e4->pwd);
}
以上代码在gcc编译器中编译通过,但运行出错!!,在cl编译器中运行出错!!
{
char name[20];
char pwd[8];
struct element* next;
};
struct element* newElement(char * name ,char * pwd)
{
struct element* p = (struct element*)malloc(sizeof(struct element));
memset(p,'/0',sizeof(struct element));
strcpy(p->name,name);
strcpy(p->pwd,pwd);
p->next=0;
return p;
}
int add(struct element * head,struct element* ele)
{
if(head == 0)
{
head=ele;
return 1;
}
while(head->next!=0)
{
head=head->next;
}
head->next=ele;
return 1;
}
struct element* search(struct element * head ,char * name)
{
if(head == 0) return 0;
while(head->next != 0)
{
printf("%d/n",head);
if(strcmp(head->name,name)==0) return head;
head= head->next;
}
return 0;
}
int main()
{
struct element* e1= newElement("meng","123456");
struct element* e2= newElement("song","123123");
struct element* e3= newElement("li","123321");
printf("%d,%d/n",add(e1,e2),add(e1,e3));
struct element* e4= search(e1,"song");
printf("song pwd is :%s/n",e4->pwd);
}
以上代码在gcc编译器中编译通过,但运行出错!!,在cl编译器中运行出错!!