Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

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
", __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
", __FILE__, __LINE__);
            exit(-1);
        }
    }
    stud->grades[course] = grade;

}

 
PREVIOUS NEXT
Tagged: #source #file
ADD COMMENT
Topic
Name
1+5 =