stack around the variable…was corrupted

Why did you declare you character buffer a size of 20? More than likely the sprintf placed more characters than that can fit in myChar.

Instead, use

  1. safer constructs such as std::ostringstream or
  2. at the very least, declare you char arrays much bigger than you would expect (not the best way, but would at least not have had the error occur).

If you’re going along the “guess the biggest size for my array” route, the last thing you want to do is attempt to count, right down to the last character, how big to make the buffer. If you’re off by a single byte, that can cause a crash.

Leave a Comment