Created
March 1, 2016 11:36
-
-
Save ibrahimab/8fc14e98a7dcbbc0cede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char *argv[]) | |
{ | |
Person *eric = createPerson("Eric", 65, 12, 165); | |
Person *ibo = createPerson("Ibrahim", 18, 100, 55); | |
personEats(eric); | |
personEats(ibo); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// other library file called person.c | |
typedef struct Person { | |
char *name; | |
int age; | |
int height; | |
double weight; | |
} Person; | |
Person *createPerson(char *name, int age, int height, double weight) | |
{ | |
Person *person = malloc(sizeof(Person)); | |
person->name = name; | |
person->age = age; | |
person->height = height; | |
person->weight = weight; | |
return person; | |
} | |
void destroyPerson(Person *person) | |
{ | |
free(person->name); | |
free(person); | |
} | |
bool personEats(Person *person) | |
{ | |
person->weight += 0.45; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment