Output code quản lý sinh viên bị miss ngày tháng năm khi dùng trên netbean, các bác vào review hộ em với ạ, em không biết mình sai ở đâu.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.c
* Author: dong dao hieu
*
* Created on August 31, 2018, 3:45 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*
*/
struct NewStudent
{
char code[100];
char name[100];
char birth[100];
float point;
};
void menu(){
printf("1. Enter student list\n");
printf("2. Look up student\n");
printf("3. Display student list\n");
printf("4. Exit\n");
printf("Please chose an option: ");
}
void Add(struct NewStudent *st,int *n)
{
printf("Student code:\n");
fgets(st[*n].code,100,stdin);
printf("Student name:\n");
fgets(st[*n].name,100,stdin);
printf("Date of birth:\n");
fgets(st[*n].birth,100,stdin);
printf("Learning point:\n");
scanf("%f",&(st[*n].point));
fpurge(stdin);
(*(n))++;
}
void LookUp(struct NewStudent *st,int *n){
char find[100];
printf("please enter a name: ");
fgets(find,100,stdin);
for(int i=0;i<*n;i++){
if(strcmp(st[i].name,find)==0)
{
printf("Student's code: \n");
puts(st[i].code);
printf("Student's name: \n");
puts(st[i].name);
printf("Date of birth: \n");
puts(st[i].birth);
printf("Learning point: \n");
printf("%.1f",st[i].point);
}
}
}
void display(struct NewStudent *st,int *n)
{
printf("student List: \n\n");
for(int i=0;i<*n;i++)
{
printf("Student's code: \n");
puts(st[i].code);
printf("Student's name: \n");
puts(st[i].name);
printf("Date of birth: \n");
puts(st[i].birth);
printf("Learning point: \n");
printf("%.1f",st[i].point);
printf("\n");
printf("===================================\n");
}
}
int main() {
int n=0;int a;
struct NewStudent *st=(struct NewStudent*)malloc(sizeof(struct NewStudent));
do{
printf("\n");
menu();
scanf("%d",&a);
fpurge(stdin);
switch(a){
case 1:{
Add(st,&n);
break;
}
case 2:{
LookUp(st,&n);
break;
}
case 3:{
display(st,&n);
break;
}
case 4:{
return(EXIT_SUCCESS);
break;
}
}
}while(a>=1&&a<=4);
return (EXIT_SUCCESS);
}