Click here to Skip to main content
15,311,716 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionproblem with sprintf_s() on win 7 Pin
Member 93537761-Nov-12 21:57
MemberMember 93537761-Nov-12 21:57 
AnswerRe: problem with sprintf_s() on win 7 Pin
Santhosh G_1-Nov-12 22:34
MemberSanthosh G_1-Nov-12 22:34 
GeneralRe: problem with sprintf_s() on win 7 Pin
Member 93537764-Nov-12 16:46
MemberMember 93537764-Nov-12 16:46 
GeneralRe: problem with sprintf_s() on win 7 Pin
Santhosh G_4-Nov-12 17:08
MemberSanthosh G_4-Nov-12 17:08 
AnswerRe: problem with sprintf_s() on win 7 Pin
CPallini1-Nov-12 22:48
mveCPallini1-Nov-12 22:48 
GeneralRe: problem with sprintf_s() on win 7 Pin
Member 93537764-Nov-12 16:46
MemberMember 93537764-Nov-12 16:46 
GeneralRe: problem with sprintf_s() on win 7 Pin
CPallini4-Nov-12 22:02
mveCPallini4-Nov-12 22:02 
AnswerRe: problem with sprintf_s() on win 7 Pin
Sarath C5-Nov-12 22:14
MemberSarath C5-Nov-12 22:14 
First thing is that, trust the implementation made by Microsoft. This is a very primitive function and you will have to read the documentation first.

Second you can your strcpy_s or strcat_s (if you're concatenating). sprint_s is not really a choice string copy.

Third your strings must be null terminated.

To understand this better, I am illustrating this with a code example

C#
char buffer[12]= {0};
int offset =3;
char Buffer[50] = "Hello World";
sprintf_s(buffer,sizeof(buffer),  "%s", Buffer);


in the above example buffer has 12 character in legnth and Hello World String contains 11 characters + null terminated. Anything less than 12 character size will raise assertion buffer too small. for sprintf_s only the number of characters being copied only matters. not really the original size of the buffers.
-Sarath.
My blog - iSpeak code

Rate the answers and close your posts if it's answered

AnswerRe: problem with sprintf_s() on win 7 Pin
Member 935377613-Nov-12 22:48
MemberMember 935377613-Nov-12 22:48 
Questionhow to get motherboard SN Pin
buffay1-Nov-12 19:42
Memberbuffay1-Nov-12 19:42 
AnswerRe: how to get motherboard SN Pin
Richard MacCutchan2-Nov-12 0:37
mveRichard MacCutchan2-Nov-12 0:37 
QuestionChart Control Pin
Tom Paronis1-Nov-12 6:04
MemberTom Paronis1-Nov-12 6:04 
AnswerRe: Chart Control Pin
Richard MacCutchan1-Nov-12 6:48
mveRichard MacCutchan1-Nov-12 6:48 
GeneralRe: Chart Control Pin
Tom Paronis1-Nov-12 7:34
MemberTom Paronis1-Nov-12 7:34 
QuestionCopy CDC Pin
_Flaviu31-Oct-12 22:29
Member_Flaviu31-Oct-12 22:29 
AnswerRe: Copy CDC Pin
Santhosh G_1-Nov-12 1:38
MemberSanthosh G_1-Nov-12 1:38 
GeneralRe: Copy CDC Pin
_Flaviu1-Nov-12 2:20
Member_Flaviu1-Nov-12 2:20 
QuestionStrange memory leak Pin
miniman0631-Oct-12 21:58
Memberminiman0631-Oct-12 21:58 
AnswerRe: Strange memory leak Pin
Sivaraman Dhamodharan31-Oct-12 22:45
MemberSivaraman Dhamodharan31-Oct-12 22:45 
GeneralRe: Strange memory leak Pin
miniman0631-Oct-12 23:10
Memberminiman0631-Oct-12 23:10 
AnswerRe: Strange memory leak Pin
Rolf Kristensen31-Oct-12 22:47
MemberRolf Kristensen31-Oct-12 22:47 
GeneralRe: Strange memory leak Pin
miniman0631-Oct-12 23:11
Memberminiman0631-Oct-12 23:11 
AnswerRe: Strange memory leak Pin
Santhosh G_31-Oct-12 23:22
MemberSanthosh G_31-Oct-12 23:22 
GeneralRe: Strange memory leak Pin
miniman0631-Oct-12 23:31
Memberminiman0631-Oct-12 23:31 
AnswerRe: Strange memory leak Pin
Jochen Arndt31-Oct-12 23:35
professionalJochen Arndt31-Oct-12 23:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.