First page Back Continue Last page Overview Graphics
Strings in C
char *buf = strdup("foo");
const char AND_BAR[] = " and bar";
char *p;
p = realloc(buf, strlen(buf) + strlen(AND_BAR) + 1);
if (p == NULL)
{
fputs("realloc failed", stderr);
free(buf);
return EXIT_FAILURE;
}
buf = p;
strcat(buf, AND_BAR);
puts(buf);
Notes:
Painful. This isn't even a complete program.