Help with returning an array

This is a discussion on Help with returning an array within the C Programming forums, part of the General Programming Boards category; Hello.
I need to return the array to my main function, but i can't get it working.
Can some one ...

char teste(char s[]) should be a char* since you want to return an array

this does not fixes the main problem - you cannot return pointer to local var.

there are 2 possibilities -
1. pass output array as parameter and fill it in the function
2. dynamically allocate memory for the array you are filling and do not forget to free it after you finish using it

But in this case the return value is assigned to a local variable in main. Wouldn't that solve the problem, like this?

Your example might work, but that would be cause it deals with a string literal. If s in st was an array instead of a pointer to the first character of a string literal, then it would mean returning a pointer to a local variable. That the return value is assigned to a local variable in main is irrelevant.

HIT_Braga: you do need extra space to hold those tokens by copying them. You cannot just store pointers to the first characters of those substrings because strtok() is destructive.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

With this code the return is an single char. if i change the op=" cr test" it will only return "c" and i need to return "cr" and "test".
There are many op:
"p 1 1" - return p and 1 and 1
"vp" - return only vp
"cr test" - return cr and test

So can how can i change the code for working nice ? making some changes on this:

of course you'll need to update the return type of the function
you'll get array of 3 pointers to the original buffer...

to support random number of parameters in the string - you'll need to implement some solution using realloc and some way to indicate number of options found - for example adding NULL pointer as last member of the array to be returned...