14

i am running a program on win 7 via visual studio 2008

and i am getting this error:

Error 4 error C3861: 'snprintf': identifier not found

i have included stdio header...

i don't know what else it can be missing

1

1 Answer 1

22

Looks like on Windows, the function is prefixed with a _. Also, the function is deprecated in favour of a safer one:

http://msdn.microsoft.com/en-us/library/2ts7cx93(v=vs.80).aspx

8
  • 6
    snprintf_s is rather stupid, snprintf already takes the size of the buffer, what benefit does asking for it twice have? If you don't want to fill the entire buffer, just give a smaller size!
    – dreamlax
    Jan 29, 2012 at 9:50
  • 28
    snprintf is a standard C function (new in C99). Microsoft's "deprecation" of it in favor of non-standard functions is highly questionable. Jan 29, 2012 at 9:51
  • 1
    It's standard in a standard that MSVC++ does not conform to. As for the deprecation's merit, I can't really speak for that. The last time I did any kind of C coding in Visual Studio was quite a long time ago. It does seem rather odd that their version of it has a size and a bufferSize. Edit: A post that outlines MS' attitude towards C99 quite well: stackoverflow.com/a/146419/567864
    – Corbin
    Jan 29, 2012 at 10:05
  • 5
    I wouldn't say that the function is prefixed with a _ on Windows. It's not the same function; _snprintf is not compliant with the C99 requirements for snprintf. In particular, _snprintf does not guarantee NUL-termination and does not return the necessary buffer size if a larger buffer is required.
    – jamesdlin
    Jan 29, 2012 at 10:34
  • 3
    snprintf and vsnprintf are added with C99 standard support in VS2014. See blogs.msdn.com/b/vcblog/archive/2014/06/18/…. Oct 29, 2014 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.