Skip to content

Instantly share code, notes, and snippets.

@Pavelovich
Created August 2, 2014 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pavelovich/9dd62924417e790c7881 to your computer and use it in GitHub Desktop.
Save Pavelovich/9dd62924417e790c7881 to your computer and use it in GitHub Desktop.
An example object I created
#include <stdio.h>
//#include <unistd.h>
#include "lib/stdfn.h"
typedef struct car {
char *color;
char *size;
int year;
} *car_t;
car_t newCar(char *color, char *size, int year)
{
car_t car = malloc(sizeof(*car));
car->color = color;
car->size = size;
car->year = year;
return car;
}
char* carColor(car_t car)
{
return car->color;
}
int main(int argc, char *argv[]) {
car_t toyota = newCar("red", "big", 2000);
char *toyotaColor = carColor(toyota);
printf("%s", toyotaColor);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment