Skip to content

Instantly share code, notes, and snippets.

@reagent
Last active December 15, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reagent/5307772 to your computer and use it in GitHub Desktop.
Save reagent/5307772 to your computer and use it in GitHub Desktop.
dat pad
char *
pad(char *in, size_t width)
{
char *padded = NULL,
*fmt = NULL;
check(asprintf(&fmt, "%%%lds", width) >= 0);
check(asprintf(&padded, fmt, in) >= 0);
free(in);
return padded;
error:
if (fmt) { free(fmt); }
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment