pointers - why dosn't this work? (patch level #1)

Roger Knopf 5502 rogerk at sco.COM
Fri Apr 6 09:28:01 AEST 1990

In article <23474 at mimsy.umd.edu> dbk at 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

More information about the Comp.lang.c mailing list