I assume you meant '\0' and not '0'.

Unless Jobn has been assigned a string previously, strcmp should fail.
(Actually it would invoke undefined behavior.)

strcpy does not care about the previous contents of the destination.
(strcat does but that is a different function.)  If the length of xxxxx plus
the terminating nul fits in Jobn, strcpy will replace as much of the
original contents as needed and will insure that it is properly terminated.
The remaining portion of Jobn will be unchanged.  Your memset serves no
apparent purpose.

:>: -----Original Message-----
:>: From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On
:>: Behalf Of Scott Ford
:>: Sent: Tuesday, September 04, 2012 12:04 PM
:>: To: IBM-MAIN@LISTSERV.UA.EDU
:>: Subject: Re: Strings (hijacked from: The IBM zEnterprise EC12
:>: announcment)
:>:
:>: I have had to move a string type field like a parameter to a field like
:>: this,
:>:
:>: Jobn   char[40];
:>:
:>: memset(Jobn,'0',sizeof(Jobn));
:>: strcpy(Jobn,xxxxx);
:>:
:>: Otherwise strcmp fails, where xxxxx is the parameter string
:>:
:>: Scott ford
:>: www.identityforge.com
:>:
:>: On Sep 4, 2012, at 1:05 PM, retired mainframer <retired-
:>: mainfra...@q.com> wrote:
:>:
:>: > The construct
:>: >     char x[3] = "ABC";
:>: > will legally initialize an array of char without adding the '\0'.  The
:>: only
:>: > restriction is that this is not a string.
:>: >
:>: > :>: -----Original Message-----
:>: > :>: From: IBM Mainframe Discussion List [mailto:IBM-
:>: m...@listserv.ua.edu] On
:>: > :>: Behalf Of John Gilmore
:>: > :>: Sent: Tuesday, September 04, 2012 9:02 AM
:>: > :>: To: IBM-MAIN@LISTSERV.UA.EDU
:>: > :>: Subject: Re: Strings (hijacked from: The IBM zEnterprise EC12
:>: > :>: announcment)
:>: > :>:
:>: > :>: If you construct an array by initializing it element by element
:>: you
:>: > :>: get an array, one that is not nul-delimited or 'of conceptually
:>: > :>: unlimited length', whatever that may mean.
:>: > :>:
:>: > :>: If you construct a string by initializing a character array with a
:>: > :>: string, you get a nul-delimited string implemented under the
:>: > :>: hood|bonnet as an array.
:>: >
:>: > ----------------------------------------------------------------------
:>: > For IBM-MAIN subscribe / signoff / archive access instructions,
:>: > send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
:>:
:>: ----------------------------------------------------------------------
:>: For IBM-MAIN subscribe / signoff / archive access instructions,
:>: send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to