3,882
社区成员




#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
char num[10];
char name[20];
char sex[4];
int cgrade;
int egrade;
int mgrade;
};
typedef struct node
{
struct student data;
struct node *next;
}Node;
Node *head,*thisn,*newn;
void printc()
{
printf("学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩\n");
}
void printe(Node *p)
{
printf("%-12s%s\t%s\t%d\t%d\t%d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade);
}
Node *Locate(Node *head,char findmess[20])
{
Node *r;
r=head;
while(r!=NULL)
{
if (strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
return 0;
}
void NewNODE(void)
{
extern Node *newn,*head,*thisn;
newn=(Node*)malloc (sizeof(Node));
if(head==NULL)
head=newn;
else
{
thisn=head;
while(thisn->next!=NULL)
thisn=thisn->next;
thisn->next=newn;
}
thisn=newn;
printf("\nenter num:");
scanf("%s", &thisn->data.num);
printf("\nenter name:");
scanf("%s", &thisn->data.name);
printf("\nenter sex:");
scanf("%s", &thisn->data.sex);
printf("\nenter egrade:");
scanf("%d", &thisn->data.egrade);
printf("\nenter mgrade:");
scanf("%d", &thisn->data.mgrade);
printf("\nenter cgrade:");
scanf("%d", &thisn->data.cgrade);
thisn->next=NULL;
printf("====大学信息管理系统====\n");
printf("1:添加学生信息 2:查找学生信息\n");
printf(" 0:退出系统 \n");
printf("请你在上述功能中选择(0-2):");
return ;
}
void Qur()
{
char findmess[20];
Node *p;
p=(Node*)malloc (sizeof(Node));
printf("请你输入要查找的学号:");
scanf("%s",&findmess);//这里应该用%s因为是字符串
p=Locate(head,findmess);
if(p)
{
printf("\t\t\t\t查找结果\n");
printc();
printe(p);
}
else
printf("\n=====>提示:没有找到该学生!\n");
}
void export()
{
if(head==NULL)
{
printf("\nemty list.\n");
return;
}
thisn=head;
do
{
printf("num:%s\n",thisn->data.num);
printf("name:%s\n",thisn->data.name);
printf("sex:%s\n",thisn->data.sex);
printf("egrade:%d\n",thisn->data.egrade);
printf("mgrade:%d\n",thisn->data.mgrade);
printf("cgrade:%d\n",thisn->data.cgrade);
thisn=thisn->next;
}while(thisn!=NULL);
}
void menu()
{
char choice;
printf("====大学信息管理系统====\n");
printf("1:添加学生信息 2:查找学生信息\n");
printf(" 0:退出系统 \n");
printf("请你在上述功能中选择(0-2):");
do
{
choice=getchar();
switch(choice)
{
case'1':NewNODE();break;
case'2':Qur();break;
case'3':export();break;
case'0':exit(0);
}
}while(1);
return;
}
int main()
{
menu();
}