求大神!大一期末做课程设计,遇到问题。关于链表。
程序代码:
//普通学生查询某门课程的得分
void chaxunmoumenke()
{
system("CLS");
int i,x;
struct work *head=NULL;
head=(struct work *)malloc(sizeof(struct work));
memset(head,0,sizeof(struct work));
head=lianbiao();
struct work *p=head;
do
{
printf("请输入需要查询的课程(课程1/课程2/课程3)[请输入1,2,3]:\n");
scanf("%d",&x);
switch(x)
{
case 1:printf(" %s \n",head->chengji1),i=1;break;
case 2:printf(" %s \n",head->chengji2),i=1;break;
case 3:printf(" %s \n",head->chengji3),i=1;break;
default:
{
i=0;
printf("没有该课程!请重新输入!");
}
}
head=head->next;
}while(x==0);
}
程序代码:
//用链表将文件里的学生基本信息读出来
struct work *lianbiao()
{
struct work *head=NULL;
struct work *node=NULL;
FILE *fp=NULL;
if((fp=fopen("jiben.txt","rb"))==NULL)
{
printf("打开文件失败!");
return NULL;
}
else
{
while(!feof(fp))
{
node=(struct work *)malloc(sizeof(struct work));
memset(node,0,sizeof(struct work));
struct work curWork;
if(fread(&curWork,sizeof(struct work),1,fp)==1)
{
node->chengji1 =curWork.chengji1;
node->chengji2 = curWork.chengji2;
node->chengji3 = curWork.chengji3;
strcpy(node->idno, curWork.idno);
strcpy(node->mima, curWork.mima);
strcpy(node->name, curWork.name);
strcpy(node->no, curWork.no);
strcpy(node->powr, curWork.powr);
node->next=head;
head=node;
}
}
}
fclose(fp);
return head;
}











啊,大神,没懂。