problem with sprintf_s() on win 7
-
char buffer[50] int offset =3; char Buffer[250]; sprintf_s(&buffer[offset],offset,"%s",Buffer); When we use the above funcation and application crashed with the folloing message --------------------------- Microsoft Visual C++ Debug Library --------------------------- Debug Assertion Failed! Program: xyz.exe File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c Line: 244 Expression: ("Buffer too small", 0) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) --------------------------- Abort Retry Ignore --------------------------- OS used : Windows 7 32bit OS Microsoft Visual Studio 2008 (VC++) Version 9.0.30729.1SP
-
char buffer[50] int offset =3; char Buffer[250]; sprintf_s(&buffer[offset],offset,"%s",Buffer); When we use the above funcation and application crashed with the folloing message --------------------------- Microsoft Visual C++ Debug Library --------------------------- Debug Assertion Failed! Program: xyz.exe File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c Line: 244 Expression: ("Buffer too small", 0) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) --------------------------- Abort Retry Ignore --------------------------- OS used : Windows 7 32bit OS Microsoft Visual Studio 2008 (VC++) Version 9.0.30729.1SP
It looks like you are trying to store a 250 character string into a 50 character buffer, and you have told the formatter that the buffer is only 3 characters long. But ultimately your code makes little sense.
One of these days I'm going to think of a really clever signature.
-
It looks like you are trying to store a 250 character string into a 50 character buffer, and you have told the formatter that the buffer is only 3 characters long. But ultimately your code makes little sense.
One of these days I'm going to think of a really clever signature.
-
A description I read had GetLastError where I expected WSAGetLastError and my searches did not return those pages. Thanks for the links.
Thanks for your time
-
It looks like you are trying to store a 250 character string into a 50 character buffer, and you have told the formatter that the buffer is only 3 characters long. But ultimately your code makes little sense.
One of these days I'm going to think of a really clever signature.
Even if make 50 char sting into a 50 char buffer, I am getting the same error. Is there any other way to do this? The same code works fine in VS6.0 and not in VS2008.
-
Even if make 50 char sting into a 50 char buffer, I am getting the same error. Is there any other way to do this? The same code works fine in VS6.0 and not in VS2008.
As I said before, you are specifying a buffer size of 3, so any number of characters greater than that will cause the error. Check the documentation[^] for specific details of the parameters and their values.
One of these days I'm going to think of a really clever signature.
-
char buffer[50] int offset =3; char Buffer[250]; sprintf_s(&buffer[offset],offset,"%s",Buffer); When we use the above funcation and application crashed with the folloing message --------------------------- Microsoft Visual C++ Debug Library --------------------------- Debug Assertion Failed! Program: xyz.exe File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c Line: 244 Expression: ("Buffer too small", 0) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) --------------------------- Abort Retry Ignore --------------------------- OS used : Windows 7 32bit OS Microsoft Visual Studio 2008 (VC++) Version 9.0.30729.1SP
Member 9353776 wrote:
char buffer[50] int offset =3; char Buffer[250]; sprintf_s(&buffer[offset],offset,"%s",Buffer);
I am trying to guess what your code is supposed to do here but this might be closer to what you want:
char buffer[50]
int offset =3;
char Buffer[250];sprintf_s(&buffer[offset], sizeof(buffer) - offset, "%s", Buffer);
The second parameter of sprintf_s as used here is the maximum allowed length of the output buffer. If the buffer is of size 50 and you want to write starting in element 3 then the obvious size remaining is 'sizeof(buffer) - offset' and not 'offset'. HTH
-- Harvey