#include #include #include /* * WARNING: this code does not comply with the coding standard! */ typedef struct { int len; int cap; char* buff; } buffer; void init_buffer(buffer* b) { b->len=0; b->cap=80; b->buff=(char*)malloc(sizeof(char)*(b->cap+1)); b->buff[0]='\0'; } void free_buffer(buffer* b) { free(b->buff); /* we don't free b because we don't own it */ } void add_to_buffer(buffer* b, char c) { if (b->len==b->cap-1) { /* need to grow the buffer */ b->cap+=80; char* temp=(char*)malloc(sizeof(char)*b->cap); strcpy(temp,b->buff); free(b->buff); b->buff=temp; } b->buff[b->len++]=c; b->buff[b->len]='\0'; } int main(int argc, char** argv) { buffer b; int i=0; for (;i