Skip to content

Instantly share code, notes, and snippets.

@ibrahimab
Created March 1, 2016 11:36
Show Gist options
  • Save ibrahimab/8fc14e98a7dcbbc0cede to your computer and use it in GitHub Desktop.
Save ibrahimab/8fc14e98a7dcbbc0cede to your computer and use it in GitHub Desktop.
#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);
}
// 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