solution.c (527B)
1 /* x = x + 'h'; */ 2 3 void pystr_append(struct pystr* self, char ch) { 4 if (self->length + 1 >= self->alloc) { 5 self->alloc += 10; 6 self->data = realloc(self->data, self->alloc); 7 } 8 self->data[self->length] = ch; 9 self->data[++self->length] = '\0'; 10 } 11 12 /* x = x + "hello"; */ 13 14 void pystr_appends(struct pystr* self, char *str) { 15 for (; *str != '\0'; ++str) { 16 pystr_append(self, *str); 17 } 18 } 19 20 /* x = "hello"; */ 21 22 void pystr_assign(struct pystr* self, char *str) { 23 self->length = 0; 24 pystr_appends(self, str); 25 }