However, as mentioned if you are expecting the value to later be used as
null-terminated string, you need to add 
Dest[8] = 0x00;
Or the value of the byte after the ending 'L' is un-predictable.


Wayne Driscoll
Product Developer
NOTE:  All opinions are strictly my own.



-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[EMAIL PROTECTED] On Behalf
Of Staller, Allan
Sent: Monday, September 08, 2008 1:49 PM
To: [email protected]
Subject: Re: question for C experts - strcpy vs memcpy

<snip>

If I am copying literal text into a char array, which do you think is 
better:

strcpy(dest,"LITERAL");

OR

memcpy(dest,"LITERAL",8);

</snip>

FWIW,

IIRC, strcpy will copy until a x'00 is encountered. This results in a
"variable length" copy. If no x'00' is encountered, strcpy will happily
copy all of storage until it tries to access un-owned storage, at which
time there will be a S0C4 (U4039 in LE terms) abend.

Memcpy will copy storage for the length indicated.

I concur with the other poster (and yourself) that memcpy is the
preferred method.

HTH,

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to