Search
 
SCRIPT & CODE EXAMPLE
 

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;

}

Comment

PREVIOUS NEXT
Code Example
C :: deleting a word with copy fuction c code 
C :: C #ifdef Directive 
C :: c code recursive function to print numbers between two numbers 
C :: len of str vbs 
C :: pathlib exclude hidden file 
C :: arduino internal pull up resistor 
C :: sOY wapo ya lo c 
C :: c get int inpot 
C :: powershell some fonts like #include are dissapearing 
C :: How can you invoke the constructor from the parent class? *ruby 
C :: User input in struct 
C :: reverse a number in c 
C :: reset c array to zero 
C :: abs() for floting point in C 
C :: first come first serve 
C :: #pragma pack(1) in c 
C :: Multi Select with icons htm; 
C :: c program boilerplate code 
C :: C static libraries creation 
C :: how we can strore a nested structure values in arrays 
C :: tetris rotate shape 
C :: anticonstitutionnellement 
C :: resize vm boot disk with empty space 
C :: qgraphicsscene save all items to file 
C :: memset c 
C :: hello world in c language 
C :: get configuration script window 7 
Dart :: dart math library 
Dart :: flutter random pick in list 
Dart :: dart timestamp 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =