Información

Autor(es) Louis Navarre & Alexandre Gobeaux
Fecha de entrega Sin fecha de envío
Tiempo límite de envío Sin límite de envío
Etiquetas de categoría s3, category_pointer, category_free, category_malloc, level4

Etiquetas

Inicia sesión

[S3] Manipulate the memory

Given the following structure university_t:

typedef struct university {
    char* city;
    int creation;
    person_t* rector;
} university_t;

And the structure person_t:

typedef struct person {
    char* name;
    int salary;
    int age;
} person_t;

You are asked to implement the functions init_all and free_all, which respectively initialises the structure university_t and frees all the memory associated with it.

The name and the city have been allocated with malloc.

Hint: all the data may not have been initialised correctly. Therefore, you have to handle all the cases (e.g. some pointers can be already NULL, and don't need to be freed).


Pregunta 1: Init all

Write the body of the function init_all. You must copy the strings.

Hint : Use strcpy.

/*
 * @city != NULL
 * @rectname != NULL
 * @return: a pointer to the university structure containing the elements
 */
 university_t* init_all(char* city, int creation, char* rectname, int age, int salary){
Pregunta 2: Free all

Write the body of the function free_all.

/*
 * Frees all the memory associated with u
 * @pre: u != NULL
 */
 void free_all(university_t* u){