Skip to content

Instantly share code, notes, and snippets.

@arttuladhar
Created July 20, 2015 05:10
Show Gist options
  • Save arttuladhar/02841ff70afbe0eb9c29 to your computer and use it in GitHub Desktop.
Save arttuladhar/02841ff70afbe0eb9c29 to your computer and use it in GitHub Desktop.
snprintf_demo
#include <slack/std.h>
#ifndef HAVE_SNPRINTF
#include <slack/snprintf.h>
#endif
int main(int ac, char **av)
{
char buf[16];
char *str = buf;
char *extra = NULL;
int len;
if (!av[1])
return EXIT_FAILURE;
if ((len = snprintf(buf, 16, "%s", av[1])) >= 16)
if (extra = malloc((len + 1) * sizeof(char)))
snprintf(str = extra, len + 1, "%s", av[1]);
printf("%s\n", str);
if (extra)
free(extra);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment