Re: String array
- From: "Vladimir S. Oka" <novine@xxxxxxxxxxxxxxx>
- Date: Tue, 11 Apr 2006 16:32:38 +0100
alex323@xxxxxxxxx opined:
Hey everybody. I am coding a function that takes a string as an
argument (char *msg) and breaks it up into pieces. The result will
be stored in (char ***fragments) which is passed as an argument. The
caller calls myfunction(mymsg, &my_fragment_array) where
`my_fragment_array' is a char **. My problem is that the array is
perfectly constructed inside the function, but when I switch frames
in GDB to see the caller, the second element of the array is either
null or memory garbage. How can I dynamically allocate an array of
strings from inside a function for use outside a function?
Well, you just need to pass the pointer to the allocated memory out of
the function. You can either return it as the return value of the
function, or you can pass a pointer to the variable you want it stored
in, and update its value inside the function.
--
Linux! Guerrilla UNIX Development Venimus, Vidimus, Dolavimus.
(By mah@xxxxxxxxxx, Mark A. Horton KA4YBR)
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
.
- References:
- String array
- From: alex323
- String array
- Prev by Date: Malloc and recursion
- Next by Date: Re: realloc(): invalid next size
- Previous by thread: String array
- Next by thread: Re: String array
- Index(es):
Relevant Pages
|
|