Click here to Skip to main content
15,913,587 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Always use memcpy instead of strcpy? Pin
Tim Smith23-Apr-03 4:10
Tim Smith23-Apr-03 4:10 
strcpy copies a given block of memory up to the point it finds a "0" or NULL in the memory block. strncpy will do the same thing up to a given number of charaters. memcpy will copy the given number of characters.

Assume you wanted to copy the following data:

ABCDE\0MNOPQ

Notice, that there is a NULL character in the 6th position.

strcpy (dst, src) would result in: ABCDE\0
strncpy (dst, src, 8) would result in: ABCDE\0
strncpy (dst, src, 3) would result in: ABC
memcpy (dst, src, 3) would result in: ABC
memcpy (dst, src, 8) would result in: ABCDE\0MN

If you want to copy raw data, use memcpy. If you want to copy C-strings (instead of std::strings) use strcpy or the safer strncpy.


Tim Smith

I'm going to patent thought. I have yet to see any prior art.
GeneralRe: Always use memcpy instead of strcpy? Pin
George224-Apr-03 0:17
George224-Apr-03 0:17 
QuestionHow to resume the file download Pin
Gowrishankar A.22-Apr-03 19:58
Gowrishankar A.22-Apr-03 19:58 
AnswerRe: How to resume the file download Pin
bryce22-Apr-03 20:57
bryce22-Apr-03 20:57 
AnswerRe: How to resume the file download Pin
Redeemer-dk23-Apr-03 1:14
Redeemer-dk23-Apr-03 1:14 
QuestionFont background? Pin
bobthemonkey22-Apr-03 19:28
bobthemonkey22-Apr-03 19:28 
AnswerRe: Font background? Pin
Rage22-Apr-03 20:36
professionalRage22-Apr-03 20:36 
AnswerRe: Font background? Pin
Anonymous22-Apr-03 20:40
Anonymous22-Apr-03 20:40 
GeneralHelp required in MFC Pin
RaajaOfSelf22-Apr-03 19:24
RaajaOfSelf22-Apr-03 19:24 
GeneralMFC-ODBC help!!!! Pin
RaajaOfSelf22-Apr-03 19:21
RaajaOfSelf22-Apr-03 19:21 
QuestionA strange CListCtrl Bug ? Pin
brraj22-Apr-03 19:18
brraj22-Apr-03 19:18 
GeneralButton with Icon on it Pin
Exceter22-Apr-03 18:59
Exceter22-Apr-03 18:59 
Generala typical problem Pin
Prog Mmer22-Apr-03 18:52
Prog Mmer22-Apr-03 18:52 
GeneralRe: a typical problem Pin
PJ Arends22-Apr-03 19:29
professionalPJ Arends22-Apr-03 19:29 
GeneralRe: a typical problem Pin
Prog Mmer22-Apr-03 21:43
Prog Mmer22-Apr-03 21:43 
GeneralRe: a typical problem Pin
Prog Mmer22-Apr-03 21:46
Prog Mmer22-Apr-03 21:46 
QuestionHow to highlight items in CTreeCtrl? Pin
Charles Liu22-Apr-03 18:40
Charles Liu22-Apr-03 18:40 
AnswerRe: How to highlight items in CTreeCtrl? Pin
Anonymous22-Apr-03 20:13
Anonymous22-Apr-03 20:13 
GeneralHighlight items in CTreeCtrl Pin
Charles Liu22-Apr-03 18:37
Charles Liu22-Apr-03 18:37 
GeneralRe: Highlight items in CTreeCtrl Pin
Rage22-Apr-03 20:29
professionalRage22-Apr-03 20:29 
GeneralAny body know error 1053 while starting service. Pin
harinath22-Apr-03 18:17
professionalharinath22-Apr-03 18:17 
GeneralRe: Any body know error 1053 while starting service. Pin
harinath22-Apr-03 18:48
professionalharinath22-Apr-03 18:48 
GeneralRe: Any body know error 1053 while starting service. Pin
Anders Molin23-Apr-03 0:56
professionalAnders Molin23-Apr-03 0:56 
GeneralRe: Any body know error 1053 while starting service. Pin
harinath23-Apr-03 1:31
professionalharinath23-Apr-03 1:31 
GeneralMatrices Pin
Albedo22-Apr-03 16:42
Albedo22-Apr-03 16:42 

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.