pointers to object content, and matching (de)alloc

This commit is contained in:
Loic Nageleisen 2013-02-01 10:39:19 +01:00
parent cbe43f63fd
commit 0191e7acf1

11
main.c
View file

@ -3,13 +3,16 @@
#include <Block.h>
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);
}