Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-lcc!styx!ames!ucbcad!ucbvax!hoptoad!farren From: farren@hoptoad.uucp (Mike Farren) Newsgroups: comp.sys.ibm.pc Subject: Re: MSC 4.0 and the Twilight Zone Message-ID: <2088@hoptoad.uucp> Date: Mon, 4-May-87 11:05:29 EDT Article-I.D.: hoptoad.2088 Posted: Mon May 4 11:05:29 1987 Date-Received: Tue, 5-May-87 01:57:52 EDT References: <2454@uw-june.UUCP> Reply-To: farren@hoptoad.UUCP (Mike Farren) Organization: Nebula Consultants in San Francisco Lines: 34 In article <2454@uw-june.UUCP> roper@uw-june.UUCP (Michael Roper) writes: >Can anyone please explain the behavior of the following few lines of code? [which doesn't work] > >main (argc, argv) >int argc; >char *argv[]; >{ > char *s; > > s = strdup (argv[1]); > strcat (s, ".U"); > do_nothing (s); >} Note that you are defining s (and, later, do_nothing_str) as a pointer to char, but you are never creating an array that the pointers will point to. As a result, the strcat and strdup routines, which expect that the pointers they receive WILL point to such arrays, go ahead and blindly copy the strings they have received as arguments to the place that the pointers point to, which is the address represented by whatever happened to be in the pointers when the routine was entered. It's amazing that the routine works as well as it does - give it "fred" as an argument, and it even works correctly - but this is just chance. Remember - pointers point to things, arrays hold things, and never the twain should meet! -- ---------------- "... if the church put in half the time on covetousness Mike Farren that it does on lust, this would be a better world ..." hoptoad!farren Garrison Keillor, "Lake Wobegon Days"