#include <stdio.h>
/*
Output (after the warnings):
buf: '0123', ret1: 4
buf: '0123456', ret2: 8
buf: '0123456', ret3: 9
buf: '0123456', ret4: 12
*/
int main() {
char buf[8];
int ret1 = snprintf(buf, 8, "0123");
printf("buf: '%s', ret1: %d\n", buf, ret1);
int ret2 = snprintf(buf, 8, "01234567");
printf("buf: '%s', ret2: %d\n", buf, ret2);
int ret3 = snprintf(buf, 8, "012345678");
printf("buf: '%s', ret3: %d\n", buf, ret3);
int ret4 = snprintf(buf, 8, "0123456789ab");
printf("buf: '%s', ret4: %d\n", buf, ret4);
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: