代码如下:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char id[500];
char password[500];
}Elemtype;
typedef struct
{
Elemtype data;
struct LNode *next;
}LNode;
LNode ListInsert(LNode *L)
{
L=(LNode*)malloc(sizeof(LNode));
L->next=NULL;
return *L;
}
LNode datasList(LNode *L)
{
char *a[]={"passqword","passworddd","password56"};
char *b[]={"1","2","3"};
LNode *boy3;
boy3=L;
int c;
for(c=0;c<3;c++)
{
Elemtype e;
strcpy(e.id,a[c]);
strcpy(e.password,b[c]);
LNode *boy2;
boy2=(LNode*)malloc(sizeof(LNode));
boy2->data=e;
boy2->next=NULL;
boy3->next=boy2;
boy3=boy2;
}
return *L;
}
int main(int argc, char *argv[])
{
LNode p,*e;
p=ListInsert(&p);
e=(datasList(&p)).next;
while(e)
{
printf("%s\t%s\n",e->data.id,e->data.password);
e=e->next;
}
system("pause");
return 0;
}
程序运行如下: