Skip to content

Instantly share code, notes, and snippets.

@alexcu
Created May 12, 2018 11:54
Show Gist options
  • Save alexcu/8f37d3b484ae02f4bc79677b82f6596e to your computer and use it in GitHub Desktop.
Save alexcu/8f37d3b484ae02f4bc79677b82f6596e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
typedef enum supermarket_t {
COLES, WOOLIES, ALDI
} supermarket_t;
typedef struct product_t {
char *name;
float price;
supermarket_t shop;
struct product_t *goes_nice_with;
} product_t;
int main(int argc, char const *argv[]) {
product_t cheese, crackers, wine;
cheese.name = "Camembert";
cheese.price = 5.60;
cheese.shop = COLES;
cheese.goes_nice_with = &crackers;
crackers.name = "Savoy";
crackers.price = 1.20;
crackers.shop = COLES;
crackers.goes_nice_with = &cheese;
wine.name = "Merlot";
wine.price = 6.90;
wine.shop = ALDI;
wine.goes_nice_with = &cheese;
printf("%s goes nice with %s\n", cheese.name, cheese.goes_nice_with->name);
printf("%s goes nice with %s\n", crackers.name, crackers.goes_nice_with->name);
printf("%s goes nice with %s\n", wine.name, wine.goes_nice_with->name);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment