Exemplo n.º 1
0
int main(int argc, char *argv[]) {

    // make two people structures
    struct person *vic = personCreate(
                        "Vicfred", 23, 173, 80);
    struct person *ana = personCreate(
                        "Anabel", 23, 160, 65);

    // print'em out and where they're in memory
    printf("Vic is at memory location %p:\n", vic);
    personPrint(vic);
    printf("Bethabel is at memory location %p:\n", ana);
    personPrint(ana);

    // make everyone age 20 years old and print'em again
    vic->age += 20;
    vic->height += 5;
    vic->weight -= 5;
    personPrint(vic);

    ana->age += 20;
    ana->weight += 5;
    personPrint(ana);

    // destroy'em both so we clean up
    personDestroy(vic);
    personDestroy(ana);

    return 0;
}
/**
 * Called by the TEAR_DOWN macro from testing_utilities.h. This function should
 * deallocate and clear all the code
 * @param examples
 */
void tearDown(Examples examples) {
	personDestroy(examples.haimMoshe);
	personDestroy(examples.oferLevi);
	personDestroy(examples.eyalGolan);
	personDestroy(examples.aviBitter);
	personDestroy(examples.idanTal);
	listDestroy(examples.list);
}
static Person personCreate(const char* name, int id) {
	assert(name);
	Person person = malloc(sizeof(struct Person_t));
	if (!person) {
		return NULL;
	}
	person->name = stringDuplicate(name);
	if (!name) {
		personDestroy(person);
		return NULL;
	}
	person->id = id;
	return person;
}
static void personDestroyHelper(ListElement element) {
	personDestroy(element);
}