问题描述
- 求助!怎么传递参数啊!
-
参数没法传递。。。。head在别的函数里是空的。。。#include<stdio.h> #include<stdlib.h> #include<string.h> #include<malloc.h> #define LEN sizeof(Student) #include <time.h> typedef struct SIS { //结构体的声明 long StudentID; //学号 char Name[20]; //姓名 char Sex[10];//性别 int Age;//年龄 char TOE[30] ;//Time of Enrollment入学日期 float GPA;//(加权平均) char PhoneNo[100]; //电话号码 char MailingAddress[100];//邮箱 struct SIS *next;//指向下一个结构体的指针 } Student; /////////////////////声明函数/////////////////////// void wellcome();//欢迎界面 void start();//开始界面 int menu();//菜单 SIS* input();//输入/插入 SIS* del(Student *head);//删除 int search (Student *head);//查找 int ALL(Student *head);//显示全部 /////////////////////////////////////////////////// void wellcome() { //欢迎界面 time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); printf("*************************************************n"); printf("*tt学生信息管理系统tt*n"); printf("*tttttt*n"); printf("*tttLAB 8ttt*n"); printf("*tttttt*n"); printf("*t 莱茵出品tt *n"); printf("*tttttt*n"); printf("*tttt2.33.vert*n"); printf("*tttttt*n"); printf("*tttttt*n"); printf("*************************************************n"); printf("%s", asctime (timeinfo)); printf("Please Press Enter to continue……"); } void start() { //开始界面 int a=0; int b=0; int A=15080121; getchar(); system("cls"); printf("nnn"); printf("tt学生信息管理系统nnn"); printf("ttt2.33.Vernnn"); getchar(); system("cls"); /* printf("tt请输入用户名和密码,按下Enter继续nnn"); printf("tAdmin:"); scanf("%d",&a); printf("n"); printf("tPassword:"); scanf("%d",&b); if(a==A&&b==A) { getchar(); system("cls"); } else { printf("ttt您没有足够的权限!!!!!nPlease Press Enter to EXIT……"); getchar(); exit(0); }*/ } int menu() {//菜单 int shuru=0; printf("nnn"); printf("tt (1)Create a student listn"); printf("tt (2)Insert a studentn");//(to the sorted array or the sorted linked list ) printf("tt (3)Delete a studentn"); printf("tt (4)Search a studentn"); printf("tt (5)Display all studentsn"); printf("tt (6)exitn"); printf("tt请选择功能:"); scanf("%d",&shuru); return shuru; } SIS* input() {//输入、插入 Student *p1,*p2; Student *student; Student *head=NULL; char a = 'y'; system("cls"); student = (Student*) malloc (LEN); printf("t请按照要求输入n"); while(a=='y'||a=='Y') { p2=p1=head; printf("tStudentID:"); scanf("%ld",&student->StudentID); printf("t"); printf("Name:"); scanf("%s",student->Name); printf("t"); printf("Sex:"); scanf("%s",&student->Sex); printf("t"); printf("Age:"); scanf("%d",&student->Age); printf("t"); printf("TOE:"); scanf("%s",&student->TOE); printf("t"); printf("GPA:"); scanf("%f",&student->GPA); printf("t"); printf("PhoneNo:"); scanf("%s",&student->PhoneNo); printf("t"); printf("MailingAddress:"); scanf("%s",&student->MailingAddress); printf("nnnn"); student->next=NULL; fflush(stdin); if(head==NULL)head=student; else { while(p1->StudentID<student->StudentID&&p1->next!=NULL) { p2=p1; p1=p1->next; } if(p1->StudentID>student->StudentID) if(p1==head) { student->next=head; head=student; } else { p2->next=student; student->next=p1; } else p1->next=student; } student = (Student *) malloc (LEN); printf("是否继续添加,输入'y'或'Y'继续n"); a=getchar(); fflush(stdin); } printf("ttt录入成功!n"); free(student); return(p1); } SIS* del(Student *head) { //删除学生信息 Student *p1,*p2; int tage = 0; long StudentID; system("cls"); p1=head; printf("ntt请输入学号:"); scanf("%d",&StudentID); if(head==NULL) { printf("不存在学生信息!n"); return 0; } while(p1!=NULL) { if(p1->StudentID==StudentID) { tage=1; if(p1==head)head=head->next; else p2->next=p1->next; free(p1); break; } p2=p1; p1=p1->next; } if(tage==0) printf("要删除的学生信息不存在!n"); tage=0; printf("ttt成功删除息n"); fflush(stdin); // system("cls"); return (head); } int search (Student *head) { //查询 Student *p1; Student *student; int tage = 0; long StudentID; system("cls"); printf("请输入要查询的学生学号:"); scanf("%d",&StudentID); p1=head; if(head==NULL) { printf("无学生信息!n"); return 0; } else while(p1!=NULL) if(p1->StudentID==StudentID) { tage=1; printf("你查找的学生信息如下:n"); printf("ttStudentID:%ldn",p1->StudentID); printf("ttName:%sn",p1->Name); printf("ttSex:%sn",p1->Sex); printf("ttAge:%dn",p1->Age); printf("ttTOE:%sn",p1->TOE); printf("ttGPA:%2fn",p1->GPA); printf("ttPhonrNo:%sn",p1->PhoneNo); printf("ttMailingAddress:%snnn",&p1->MailingAddress); break; } else p1=p1->next; if(tage==0)printf("ttt无该学生信息!n"); tage=0; fflush(stdin); return 0; } int ALL(Student *head) { //显示全部信息 Student *p1; p1 = head; system("cls"); if(head==NULL) { printf("无学生信息!n"); return 0; } while(p1!=NULL) { printf("ttStudentID:%ldn",p1->StudentID); printf("ttName:%sn",p1->Name); printf("ttSex:%sn",p1->Sex); printf("ttAge:%dn",p1->Age); printf("ttTOE:%sn",p1->TOE); printf("ttGPA:%2fn",p1->GPA); printf("ttPhonrNo:%sn",p1->PhoneNo); printf("ttMailingAddress:%snn",p1->MailingAddress); p1=p1->next; } return 0; } main() { int choose; int x=1; Student *head=NULL; wellcome(); start(); while(x) { choose=menu(); switch(choose) { case 1: { input(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 2: { input(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 3: { del(head); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 4: { search(head); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 5: { ALL(head); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 6: { exit(1); } default: { system("cls"); printf("nnnttt无此功能nnnn"); break; } } } }
解决方案
问题能再明确点吗?。。。
时间: 2024-09-15 21:58:16