Value and type of last evaluated expression: Address of array element: Address of array elementx: (none)
Your browser does not support the canvas element
which will make some the features unavailable.
If you are using Internet Explorer within the University of Exeter
try going to the Settings menu (probably the gear shape at the top right
of this page),
selecting "Compatibility View settings",
unchecking "Display intranet sites in Compatibility View"
and reloading this page.
Code
Header...
// An extendable string
typedef struct string {
char *text;
int len;
int buflen;
}String;
// Amount to allocate at a time
#define N 8
// Internal function
» if (s==NULL) {// Create a new String
»s=xmalloc(sizeof *s);
»s->buflen=s->len=0;
»s->text=NULL;
}
» if (addstr==NULL) // Just create a new empty String
return s;
» if (len+s->len>=s->buflen) {// Extend text buffer
»s->buflen=1+len+s->len;
»s->buflen+=N-s->buflen%N;// Make it a multiple of N
»s->text=realloc(s->text, s->buflen);
}
»strcpy(s->text+s->len, addstr);
»s->len+=len;
» return s;