run-time check faluire #2 stack around the variable is corrupted

I am getting an error for the following code

char tmpMaxCompression[19];
double MinVal = 0.0;

//MinVal is dynamic input from the user

sprintf_s( tmpMaxCompression, _countof(tmpMaxCompression) + 1 , "19.2%d" , MinVal );

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The error - run-time check failure #2 - stack around the variable 'tmpMaxCompression' was corrupted
ndensonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
StanyslawConnect With a Mentor Commented:
> char tmpMaxCompression[19];
...
> sprintf_s( tmpMaxCompression, _countof(tmpMaxCompression) + 1 , "19.2%d" , MinVal );

20 chars (including termination '\0') are written to array of size 19
to fix: increase array size, decrease 2nd arg of sprintf_s

char tmpMaxCompression[20];
...
sprintf_s( tmpMaxCompression, _countof(tmpMaxCompression) , "19.2%d" , MinVal );
0
All Courses

From novice to tech pro — start learning today.