Permalink
Browse files

ex16

  • Loading branch information...
1 parent 3302ae3 commit 90934996c4fb894a83b758ab56a540102350f290 @aubreyrhodes committed Jan 10, 2013
Showing with 64 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +6 −0 ex16/Makefile
  3. 0 ex16/build/.gitkeep
  4. +57 −0 ex16/ex16.c
View
@@ -1,3 +1,4 @@
*.dSYM
build/*
+**/build/*
.vagrant
View
@@ -0,0 +1,6 @@
+CFLAGS=-Wall -g
+
+all:
+ cc $(CFLAGS) ex16.c -o build/ex16
+clean:
+ rm -rf build/*
View
No changes.
View
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct Person {
+ char *name;
+ int age;
+ int height;
+ int weight;
+};
+
+struct Person Person_create(char *name, int age, int height, int weight)
+{
+ struct Person who;
+
+ who.name = strdup(name);
+ who.age = age;
+ who.height = height;
+ who.weight = weight;
+
+ return who;
+}
+
+void Person_destroy(struct Person who)
+{
+ free(who.name);
+}
+
+void Person_print(struct Person who)
+{
+ printf("Name: %s\n", who.name);
+ printf("\tAge: %d\n", who.age);
+ printf("\tHeight: %d\n", who.height);
+ printf("\tWeight: %d\n", who.weight);
+}
+
+int main(int number_of_arguments, char *argument_values[])
+{
+ struct Person joe = Person_create(
+ "Joe Alex", 32, 64, 140);
+
+ struct Person frank = Person_create(
+ "Frank Blank", 20, 72, 180);
+
+ /* printf("Joe is at memory location: %p\n", joe); */
+ Person_print(joe);
+
+
+ /* printf("Frank is at memory location: %p\n", frank); */
+ Person_print(frank);
+
+ Person_destroy(joe);
+ Person_destroy(frank);
+
+ return 0;
+}

0 comments on commit 9093499

Please sign in to comment.