size_t alloc;
void (*expand)(struct _cstring_t *self, char x);
void (*expand_arr)(struct _cstring_t *self, char *x);
+ void (*reset)(struct _cstring_t *self);
void (*delete)(struct _cstring_t *self);
} cstring_t;
void cstring_expand(cstring_t *self, char x);
void cstring_expand_arr(cstring_t *self, char *x);
+void cstring_reset(cstring_t *self);
void cstring_delete(cstring_t *self);
cstring_t *cstring_init() {
x->size = x->alloc = 0;
x->expand = cstring_expand;
x->expand_arr = cstring_expand_arr;
+ x->reset = cstring_reset;
x->delete = cstring_delete;
return x;
}
self->size = strlen(self->text);
}
+void cstring_reset(cstring_t *self) {
+ free(self->text);
+ self->text = (void*)0;
+ self->size = self->alloc = 0;
+}
void cstring_delete(cstring_t *self) {
free(self->text);
(p->expand)(p, 'X'); printf("text: %s, size: %i, alloc: %i\n", p->text, p->size, p->alloc);
(p->expand)(p, 'X'); printf("text: %s, size: %i, alloc: %i\n", p->text, p->size, p->alloc);
- (p->delete)(p);
-
- // testing with char array
- p = cstring_init();
+ (p->reset)(p);
printf("text: %s, size: %i, alloc: %i\n", p->text, p->size, p->alloc);
char x[2] = {'X', '\0'};