Skip to content

Instantly share code, notes, and snippets.

@nokute78
Last active December 20, 2016 12:24
Show Gist options
  • Save nokute78/dfb8063a8d605d5998d767d63b3eb727 to your computer and use it in GitHub Desktop.
Save nokute78/dfb8063a8d605d5998d767d63b3eb727 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void report(int i)
{
printf("[%s] %d\n", __FUNCTION__, i);
}
int main(void)
{
char buf[32] = {0};
report( snprintf(buf, sizeof(buf), "%d",123) );
printf("len=%ld\n", strlen(buf));
report( snprintf(buf, sizeof(buf), "%f",123.456) );
printf("len=%ld\n", strlen(buf));
/* Output
[report] 3
len=3
[report] 10
len=10
*/
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment