Xref: utzoo comp.lang.c:27683 comp.unix.xenix:10986 Path: utzoo!censor!geac!jtsv16!uunet!sco!rogerk From: rogerk@sco.COM (Roger Knopf 5502) Newsgroups: comp.lang.c,comp.unix.xenix Subject: Re: pointers - why dosn't this work? (patch level #1) Message-ID: <4135@scorn.sco.COM> Date: 5 Apr 90 23:28:01 GMT References: <23467@mimsy.umd.edu> <23474@mimsy.umd.edu> Sender: news@sco.COM Reply-To: rogerk@sco.COM (Roger Knopf 5502) Distribution: usa Organization: The Santa Cruz Operation, Inc. Lines: 22 In article <23474@mimsy.umd.edu> dbk@mimsy.umd.edu (Dan Kozak) writes: There is an even easier way >Actually it is 3 uninitialized pointers. The first fix still works, >but if you want to keep a declared as in the original, add > > a[0] = (char *) malloc(sizeof(x) + 1); /* this */ > strcpy(a[0], x); Instead of the preceding two lines, use: a[0] = strdup(x); strdup(S) automagically does the malloc for you and returns a pointer to where it duped the string. Roger Knopf SCO Consulting Services -- "His potential clients were always giving him the business." --Robert Thornton