1 #if !defined( CSTRING_H )
5 * A implementation of expandable c strings in heap memory.
7 * struct: cstring_t which defines a expandable c string type in heap memory
9 * function: cstring_init to intialize struct of type cstring_t
10 * function: cstring_t->expand to add one character to the struct
11 * function: cstring_t->expand_arr to add a string to the struct
12 * function: cstring_t->reset to clear and reuse the struct
13 * function: cstring_t->delete to free the allocated memory
16 * cstring_t *p = cstring_init();
17 * (p->expand)(p, 'X');
22 // The amount of memory allocated from heap when string expansion hits the
23 // allocated memory limit
24 #define REALLOC_ADD 10
26 typedef struct _cstring_t {
30 void (*expand)(struct _cstring_t *self, char x);
31 void (*expand_arr)(struct _cstring_t *self, char *x);
32 void (*reset)(struct _cstring_t *self);
33 void (*delete)(struct _cstring_t *self);
36 cstring_t *cstring_init();
37 void cstring_expand(cstring_t *self, char x);
38 void cstring_expand_arr(cstring_t *self, char *x);
39 void cstring_reset(cstring_t *self);
40 void cstring_delete(cstring_t *self);
42 #endif // !defined( CSTRING_H )