改正代码#include stdioh#include stdlibh#include stringh #define OK 1typedef char Status;typedef struct SqNode Status num4flight7name5ID19state5; struct SqNode next;LNodeLinkList;int InitListLinkList &L L=
改正后的代码:
#include <stdio.h> #include <stdlib.h> #include <string.h>
#define OK 1
typedef char Status;
typedef struct SqNode{ Status num[4],flight[7],name[5],ID[19],state[5]; struct SqNode *next; }LNode,*LinkList;
int InitList(LinkList &L) { L=(LinkList)malloc(sizeof(LNode)); L->next=NULL; return OK; }
int creatList(LinkList &Q) { Q->next = (LinkList)malloc(sizeof(LNode)); strcpy(Q->next->num, "001"); strcpy(Q->next->flight, "UC8866"); strcpy(Q->next->name, "张里"); strcpy(Q->next->ID, "510199909090002"); strcpy(Q->next->state, "到达"); Q = Q->next;
Q->next = (LinkList)malloc(sizeof(LNode));
strcpy(Q->next->num, "002");
strcpy(Q->next->flight, "NI7755");
strcpy(Q->next->name, "李丽");
strcpy(Q->next->ID, "510200012290001");
strcpy(Q->next->state, "已取");
Q = Q->next;
Q->next = (LinkList)malloc(sizeof(LNode));
strcpy(Q->next->num, "003");
strcpy(Q->next->flight, "MQ9090");
strcpy(Q->next->name, "王一");
strcpy(Q->next->ID, "510198810090003");
strcpy(Q->next->state, "未取");
Q = Q->next;
Q->next = (LinkList)malloc(sizeof(LNode));
strcpy(Q->next->num, "004");
strcpy(Q->next->flight, "BU8080");
strcpy(Q->next->name, "赵山");
strcpy(Q->next->ID, "610197708080022");
strcpy(Q->next->state, "未到达");
Q->next->next = NULL;
return OK;
}
int seekList(LinkList L,char a[])
{
while(L)
{
if(strcmp(L->ID,a)==0)
{
printf("%s\n",L->state);
return OK;
}
L=L->next;
}
printf("查无此人\n");
return 0;
}
int main() { char c[19]; LinkList L; InitList(L); creatList(L); printf("欢迎光临\n请输入身份证查找行李信息\n"); scanf("%s",c); seekList(L->next,c); return 0; }
修改说明:
-
函数名应该按照驼峰命名法,如InitList改为initList。
-
函数返回值应该有明确的含义,如InitList应该返回初始化是否成功的状态信息。
-
在定义结构体时,应该使用typedef,并且遵循命名规范,如SqNode改为LNode。
-
在定义结构体时,应该将指针放在结构体的后面,方便理解。
-
在函数中传递链表时,应该传递链表的头结点,而不是头指针。
-
在函数中使用字符串时,应该使用%s来读取和输出字符串,而不是%d。
-
在字符串比较时,应该使用strcmp函数,而不是==运算符。
-
在函数中,应该使用大括号将语句块括起来,增加代码的可读性。
-
在读取字符串时,应该避免使用空格,否则会读入空格
原文地址: https://www.cveoy.top/t/topic/fpYG 著作权归作者所有。请勿转载和采集!