| re: function returning array of strings
"shyam" <shyam.geek@gmail.com> wrote[color=blue]
> I have to write a function which basically takes in a string and
> returns an unknown number( at compile time) of strings
>
> i hav the following syntax in mind
>
> char *tokenize(char *)[]
>
> is it ok?
>
> if yes then how do i call the function inside a code?
>
> Suppose it returns 3 strings then
>
> i must hav something like
>
> char *c[3];
>
>
> c = tokenize(/*the string*/)[];
>
> is this the correct way to declare and use function returning arrays of
> string?
>[/color]
No.
char **tokenize(char *string)
{
/* pass through the string, countin white space or other delimiters */
/* this tells you how many tokens - allocate an array of pointer to hold
them, which you return */
/* then pass thorugh again, pulling out all the tokens. Probably you want to
duplicate them
one at a time, holding the results in the array you return */
/* finally, caller probably wants some way of knowing how many tokens were
parsed. Either set an integer pointer, passed in, or set the last element of
the array to NULL. */
} |