Created
July 20, 2015 05:10
-
-
Save arttuladhar/02841ff70afbe0eb9c29 to your computer and use it in GitHub Desktop.
snprintf_demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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