I am confused with snprintf function. First of all, I did not find the snprintf function in the turbo C version compiler under stdio.h Secondly, in the GNU compiler, snprintf returns -1 when the buffer size is smaller than the formatted string, although it should return the number of characters that would be printed. if the buffer size was big enough. I have the following source:
#include<stdio.h>
int main()
{
char str[100];
int numchar = snprintf(str,2,"ello jdj");
printf("%d\n",numchar);
return 0;
}
This code should output 8 according to what I know about snprintf. but it returns -1 in my GNU compiler. What are the facts?
source
share