Click here to Skip to main content
15,909,193 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Get Selected Text Pin
Rajesh R Subramanian11-Dec-06 19:51
professionalRajesh R Subramanian11-Dec-06 19:51 
GeneralRe: Get Selected Text Pin
Mahesh Kulkarni11-Dec-06 19:57
Mahesh Kulkarni11-Dec-06 19:57 
GeneralRe: Get Selected Text Pin
Rajesh R Subramanian11-Dec-06 20:13
professionalRajesh R Subramanian11-Dec-06 20:13 
QuestionString command differences Pin
Oliver12311-Dec-06 12:18
Oliver12311-Dec-06 12:18 
AnswerRe: String command differences Pin
Mark Salsbery11-Dec-06 12:57
Mark Salsbery11-Dec-06 12:57 
AnswerRe: String command differences Pin
George L. Jackson11-Dec-06 15:05
George L. Jackson11-Dec-06 15:05 
AnswerRe: String command differences Pin
prasad_som11-Dec-06 17:44
prasad_som11-Dec-06 17:44 
AnswerRe: String command differences Pin
James R. Twine12-Dec-06 1:59
James R. Twine12-Dec-06 1:59 
   The results will be almost the same, save for the fact that the sprintf(...) example will place two NUL characters at the end of the string.

   The sprintf(...) function is designed to build a formatted string using a variable list of parameters, and it can do this formatting in many different ways.  As a result, its implementation is somewhat complex, and it may take longer to run than a call to strcpy(...) in this simple case.

   The strcpy(...) function is designed to copy strings.  As such, its implementation is much simpler, and it may execute faster than sprintf(...).

   Both functions have the potential to overrun the target buffer, because they (as shown) will not limit the data copied to the buffer.  Using a function like strncpy(...) allows you to enforce the amount of data copied to the target buffer, but you may have to watch out for a missing terminating NUL character in some cases.

   Not that you asked, but I would suggest using strcpy(...)/strncpy(...) for copying strings - that is what they were designed to do and what they are generally optimized for.  IMHO, using functions like printf(...)/sprintf(...) for static/constant strings indicates either a lack of understanding or a unconscious need to use a shotgun to kill a fly! Smile | :)

   Peace!

-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites
(Please rate this post!)

GeneralRe: String command differences Pin
Mark Salsbery12-Dec-06 8:04
Mark Salsbery12-Dec-06 8:04 
GeneralRe: String command differences Pin
James R. Twine13-Dec-06 2:34
James R. Twine13-Dec-06 2:34 
GeneralRe: String command differences Pin
Mark Salsbery13-Dec-06 5:17
Mark Salsbery13-Dec-06 5:17 
QuestionWhy is Visual before Visual C++? Pin
Code232611-Dec-06 11:18
Code232611-Dec-06 11:18 
AnswerRe: Why is Visual before Visual C++? Pin
Fernando A. Gomez F.11-Dec-06 14:56
Fernando A. Gomez F.11-Dec-06 14:56 
AnswerRe: Why is Visual before Visual C++? Pin
George L. Jackson11-Dec-06 15:12
George L. Jackson11-Dec-06 15:12 
AnswerRe: Why is Visual before Visual C++? Pin
ThatsAlok11-Dec-06 17:35
ThatsAlok11-Dec-06 17:35 
GeneralRe: Why is Visual before Visual C++? Pin
Sam Hobbs12-Dec-06 16:15
Sam Hobbs12-Dec-06 16:15 
GeneralRe: Why is Visual before Visual C++? Pin
Code232613-Dec-06 11:00
Code232613-Dec-06 11:00 
AnswerRe: Why is Visual before Visual C++? Pin
Sam Hobbs12-Dec-06 16:17
Sam Hobbs12-Dec-06 16:17 
QuestionAntother SQL db implementation question Pin
Jim Crafton11-Dec-06 11:15
Jim Crafton11-Dec-06 11:15 
AnswerRe: Antother SQL db implementation question Pin
cmk11-Dec-06 11:48
cmk11-Dec-06 11:48 
GeneralRe: Antother SQL db implementation question Pin
Jim Crafton11-Dec-06 17:11
Jim Crafton11-Dec-06 17:11 
GeneralRe: Antother SQL db implementation question Pin
cmk11-Dec-06 20:45
cmk11-Dec-06 20:45 
QuestionStaring with a Dialog Pin
manustone11-Dec-06 10:49
manustone11-Dec-06 10:49 
AnswerRe: Staring with a Dialog Pin
Michael Dunn11-Dec-06 10:55
sitebuilderMichael Dunn11-Dec-06 10:55 
GeneralRe: Staring with a Dialog Pin
manustone11-Dec-06 11:28
manustone11-Dec-06 11:28 

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.