Mọi người cho em hỏi đoạn Code sai ở đâu ạ , đây là đề bài:
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
#include<string.h>
struct AllSchool
{
char name[20];
int official_count;
int student_count;
struct AllSchool *next;
};
typedef struct AllSchool *School;
School AddHead(School List,char ten[], int socanbo, int sosinhvien) {
School p = (School)malloc(sizeof(struct AllSchool));
strcpy(p->name, ten);
p->official_count = socanbo;
p->student_count = sosinhvien;
p->next = List;
List = p;
return List;
}
//Nhap truong
void Input(School List) {
char stop;
char ten[20];
int socanbo, sosinhvien, dem = 1;
do {
printf("Nhap thong tin truong thu %d : \n", dem );
printf("Nhap ten truong : ");
fflush(stdin);
gets(ten);
printf("Nhap so can bo : "); scanf("%d", &socanbo);
printf("Nhap so sinh vien : "); scanf("%d", &sosinhvien);
AddHead(List,ten,socanbo,sosinhvien);
dem++;
printf("\nPress ESC to Stop >< AnyKey to Continue !\n");
stop = getch();
} while (stop != 27);
}
//
// void printlist(School List){
// for(School p=List;p!=NULL;p=p->next) printf("%s\t",p->name );
// }
//Truong nhieu sinh vien nhat
void MaxStudent(School List) {
School max = List;
School p=List;
while(p->next!=NULL){
if( (max->student_count)<(p->student_count) ) max=p;
p=p->next;
}
printf("Truong co nhieu sinh vien nhat la : \n");
printf("Ten : %s ", max->name);
printf("So can bo : %d", max->official_count);
printf("So sinh vien : %d", max->student_count );
}
int main() {
School List = NULL;
Input(List);
MaxStudent(List);
return 0;
}