Lỗi lưu file trong chương trình quản lý sinh viên

Em lưu vào 1 file nhưng chương trình nó chỉ lưu được từ thằng thứ 2 trở đi.
Mong anh chị giúp đỡ em. Em cám ơn.

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 choice an option: “);
}

void Add(struct NewStudent st,FILE *fp)// problem when add the first student i can add the second student and others student.
{
    fp=fopen(“student.txt”,“ab”);// open the file
    printf(“Student code:\n”);
    fgets(st.code,100,stdin);// get code of student
    printf(“Student name:\n”);
    fgets(st.name,100,stdin);// get name of student
    printf(“Date of birth:\n”);
    fgets(st.birth,100,stdin);// get birth of student
    printf(“Learning point:\n”); 
    scanf(”%f”,&st.point);// get learning point
    fpurge(stdin); 
    fwrite(&st,sizeof(st),1,fp);// store struct into a file
    fclose(fp);
}
int main() {
    int a;struct NewStudent st;FILE *fp;
    do{
        printf("\n");
        menu();
        scanf("%d",&a);// scan number of choice
        fpurge(stdin);
        switch(a){
            case 1:{
                Add(st,fp);
                break;
            }
            case 4:{
                return(EXIT_SUCCESS);// quit program
                break;
            }
        }
    } while(a>=1&&a<=4);// condition to chose funtion
    return (EXIT_SUCCESS);
}

Đã lấy phần thay đổi của Aragami vào post #1
A post was merged into an existing topic: Topic lưu trữ các post off-topic - version 3

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?