编辑代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct LNode {
 char Areacode[20];
 char Cityname[20];
 struct LNode* next;
}LinkNode;

void CreateLink(LinkNode **L, char Areacode[][20], char Cityname[][20], int n) {
(*L) = (LinkNode*)malloc(sizeof(LinkNode));
(*L)->next = NULL;
 LinkNode*s;
 for (int i = 0; i < n; i++) {
  s = (LinkNode*)malloc(sizeof(LinkNode));

  strcpy(s->Areacode,Areacode[i]);
  strcpy(s->Cityname,Cityname[i]);
  s->next =(*L)->next;
  (*L)->next = s;
 }

}

void PrintLink(LinkNode* L) {
 LinkNode* p = L->next;
 while (p) {
  printf("%s %s\n", p->Areacode, p->Cityname);
  p = p->next;
 }
}


int main() {
 LinkNode *L;
 char Areacode[5][20] = {"010", "021", "034", "024", "015"};
 char Cityname[5][20] = {"Beijing","Wuhan","Shanghai","Guangzhou","Shenzhen"};
 /*CreateLink(&L, Areacode, Cityname, 5);*/
 /*PrintLink(L);*/

 L = (LinkNode*)malloc(sizeof(LinkNode));
 L->next = NULL;
 LinkNode *s;
 for (int i = 0; i < 5; i++) {
  s = (LinkNode*)malloc(sizeof(LinkNode));

  strcpy(s->Areacode,Areacode[i]);
  strcpy(s->Cityname,Cityname[i]);
  s->next =L->next;
  L->next = s;
 }

 while (L->next) {
  printf("%s %s\n", L->Areacode, L->Cityname);
  L = L->next;
 }

}