Answers for "example of source file"

C
0

example of source file

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Student.h"

struct Student {
    char name[64];
    char id[16];
    Grade grades [MAX_COURSES];
};

Grade StudentGetGrade(Student * stud, Grade grade) {
    return stud ->grades[grade];
}
Student * StudentCreate(const char * name , const char * id) {
    Student *stud  = calloc(1, sizeof(Student));
    if (!stud) {
        fprintf(stderr, "%s, %d: Failed to allocate memory\n", __FILE__, __LINE__);
        exit(-1);
    }
    strcpy(stud->name, name);
    strcpy(stud->id, id);
    memset(stud,NO_GRADE, MAX_COURSES);
    return stud;
}

void StudentDestroy(Student* student) {
    free(student);
}


void StudentSetGrade(Student*  stud , Course course, Grade grade ){
    if( (course > MAX_COURSES) ){
        if (!stud) {
            fprintf(stderr, "%s, %d: Failed to allocate memory\n", __FILE__, __LINE__);
            exit(-1);
        }
    }
    stud->grades[course] = grade;

}
Posted by: Guest on April-28-2022

Code answers related to "C"

Browse Popular Code Answers by Language