Dave's Brain

Browse - Programming Tips - How do I use _snprintf_s() and why is it crashing?

Date: 2010mar17
Language: C/C++

Q.  How do I use _snprintf_s() and why is it crashing?

A.  The regular way to is it is:

char buf[1000]; _snprintf_s(buf, sizeof(buf), _TRUNCATE, ...);
But this crashes More info: http://connect.microsoft.com/VisualStudio/feedback/details/289013/snprintf-s-causes-array-out-of-bounds-write-when-the-truncate-flag-is-used-for-count So modify your stdlib.h file as explained there or use _snprintf() like this:
_snprintf(buf, sizeof(buf), ...);

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.