I'm so confused, I'm sorry if this obvious, but:
int main()
{
char stringDest[20];
char stringSource[20];
strcpy_s(stringDest, stringSource);
return 0;
}
Throws the exception "Buffer is too small". Whereas:
char stringSource[20];
int main()
{
char stringDest[20];
strcpy_s(stringDest, stringSource);
return 0;
}
Works fine.
Furthermore, I thought the point of the safe strcpy_s(dest, size, source)
was that you specify the number of bytes that are copied, however when I do this:
int main()
{
char stringDest[20];
char stringSource[20];
strcpy_s(stringDest, 1, stringSource);
return 0;
}
I get a "Buffer is too small exception".
I am so confused. Why does declaring the variable outside main()
make a difference? And why is it wrong to specify 1 byte to copy?