pointer->pointer problem

Frank B. Mostek mostek at motcid.UUCP
Sat Apr 6 08:26:15 AEST 1991


reilly at bnlux1.bnl.gov (kevin reilly) writes:

>main()
>{
>char **outPt;

>outPut = FUNC1(...);
>FUNC2(outPut);
>}

>char **FUNC1(...)
>{
>static char *lines[10];
        ^^^^^^^^^^^^^^^
You have commited the dreaded C string memory allocation error.
Your problem is analogous to the following:

char *p;

strcpy(p, "BLOW AWAY SOME MEMORY, HOPEFULLY YOUR OS HAS MEM PROTECTION");

You need to allocate space for each pointer.

E.g.  line[1] = malloc(strlen(str) + 1);	/* Normally called strsave() */
      strcpy(line[1], str);

OR, you could declare a 2 dimensional array. (if you know in advance how big
everything is going to be.)

Hope this helps.
-- 
************************************************************
Frank Mostek			uunet!motcid!amethyst!mostek
Software Consultant 		(708)632-7191
************************************************************



More information about the Comp.lang.c mailing list