Skip to content

Instantly share code, notes, and snippets.

@oerdnj
Created March 24, 2016 16:13
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 oerdnj/db040b7f489d2ed84e27 to your computer and use it in GitHub Desktop.
Save oerdnj/db040b7f489d2ed84e27 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
/* just make sure sizeof(out) is at least sz+1 large */
#define left_pad(out, sz, s) snprintf(out, sz+1, "%.*s", sz, s)
#define left_pad_str(out, sz, s, pad) snprintf(out, sz+1, "%.*s%s", (sz < strlen(s)) ? 0 : sz - strlen(s), pad, s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment