snprintf confusion

c, printf, string

Solution

It sounds like you are using an old version of glibc. From the man page for `snprintf`:

The glibc implementation of the functions snprintf() and vsnprintf() conforms to the C99 standard, that is, behaves as described above, since glibc version 2.1. Until glibc 2.0.6 they would return -1 when the output was truncated.

Problem

I am confused with snprintf function. First of all I have not found the function snprintf in a turbo C version compiler under stdio.h Secondly in a GNU compiler snprintf is returning -1 when buffer size is smaller than formatted string ,though it should return the number of characters would have been printed if buffer size was sufficiently large. I have 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 as I know about snprintf so far. but it is returning -1 in my GNU compiler. What are the facts behind?

Original source