MESSAGE
| DATE | 2005-01-25 |
| FROM | From: "Martin, Jared"
|
| SUBJECT | RE: [hangout] Simple C question
|
From owner-hangouts-destenys-at-mrbrklyn.com Tue Jan 25 16:36:50 2005 X-UIDL: 4`-"!PB?"!O]E"!*2$"! Received: from www2.mrbrklyn.com (localhost [127.0.0.1]) by mrbrklyn.com (8.12.11/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id j0PLanGH008337 for ; Tue, 25 Jan 2005 16:36:49 -0500 Received: (from mdom-at-localhost) by www2.mrbrklyn.com (8.12.11/8.12.3/Submit) id j0PLanNS008336 for hangouts-destenys; Tue, 25 Jan 2005 16:36:49 -0500 X-Authentication-Warning: www2.mrbrklyn.com: mdom set sender to owner-hangouts-at-www2.mrbrklyn.com using -f Received: from DGEXCHANGE03.DGLAW.COM (exchange.dglaw.com [216.91.14.105]) by mrbrklyn.com (8.12.11/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id j0PLam2o008331 for ; Tue, 25 Jan 2005 16:36:48 -0500 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Subject: RE: [hangout] Simple C question Date: Tue, 25 Jan 2005 16:36:56 -0500 Message-ID: <9A6B8130C7F3BD49AC80282BE493A7DB262C47-at-DGEXCHANGE03.DGLAW.COM> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [hangout] Simple C question thread-index: AcUDIYg31hIIhR+/SXmpDESbi2HHkgABElig From: "Martin, Jared" To: "Billy" Cc: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mrbrklyn.com id j0PLam2o008331 Sender: owner-hangouts-at-mrbrklyn.com Precedence: bulk Reply-To: "Martin, Jared" List: New Yorker GNU Linux Scene Admin: To unsubscribe send unsubscribe name-at-domian.com in the body to hangout-request-at-www2.mrbrklyn.com X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on www2.mrbrklyn.com X-Spam-Status: No, score=-2.6 required=4.0 tests=BAYES_00 autolearn=ham version=3.0.0 X-Spam-Level: X-Keywords: X-UID: 38534 Status: RO Content-Length: 1718 Lines: 81
Thanks a lot, I had seen strcpy, but strncpy is what I really needed Thanks.
Sincerely, ***************************** Jared Martin IT Desktop Support Davis & Gilbert LLP 1740 Broadway New York, NY 10019 Help Desk: 212-237-1500 Office: 212-237-1504 Cell: 646-773-4138 Fax: (212) 974-7023 *************************************
-----Original Message----- From: Billy [mailto:billy-at-dadadada.net] Sent: Tuesday, January 25, 2005 4:03 PM To: Inker, Evan Cc: Martin, Jared; NYLXS Subject: Re: [hangout] Simple C question
Inker, Evan wrote: > Check this out > > strcopy.c > > /* strcopy.c written by detour-at-metalshell.com > * > * example of a string copying function. > * > * http://www.metalshell.com/ > * > */ > > #include > #include > > void strcopy(const char *, char *); > > int main() { > char string1[] = "This is string1"; > char string2[] = "This is string2"; > > strcopy(string1, string2); > printf("String2: %s", string2); > } > > void strcopy(const char * str1, char * str2) { > int x = 0; > > /* change the size of string2 to the size of string1 */ > realloc(str2, sizeof(str1)); > > do { > str2[x] = str1[x]; > } while (str1[x++] != '\0'); > > }
This program is incorrect. YOU CANNOT overwrite the contents of string2. It is also illegal to realloc() a pointer which was not obtained by malloc(). also, realloc is free to move the block. you have to use its return value to update the pointer. There's just so much wrong...
I DON'T RECOMMEND learning from this example.
____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|