From 0191e7acf1e85926666ba7b6f1e8a73f79adb9c5 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 1 Feb 2013 10:39:19 +0100 Subject: [PATCH] pointers to object content, and matching (de)alloc --- main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index d0e237e..54addf6 100644 --- a/main.c +++ b/main.c @@ -3,13 +3,16 @@ #include struct Post_s { - char author[255]; - char body[2048]; + char *author; + char *body; }; typedef struct Post_s Post; Post *Post_alloc() { - return malloc(sizeof(Post)); + Post *new = malloc(sizeof(Post)); + new->author = malloc(255); + new->body = malloc(1024); + return new; } void Post_init(Post *self) { @@ -22,6 +25,8 @@ void Post_printf(Post *self) { } void Post_dealloc(Post *self) { + free(self->body); + free(self->author); free(self); }