How do I return an string from a function.
VB:
Code:void main { Char str[]; str=getstr(): printf("%s",str); } getstr() { string="I work"; }
How do I return an string from a function.
VB:
Code:void main { Char str[]; str=getstr(): printf("%s",str); } getstr() { string="I work"; }
You can't return arrays, only pointers to char and pointers to arrays. So your code would look like this:
Code:char *getstr() { return "I work"; } int main { char *str; str = getstr(): printf("%s", str); }
The information given in this message is known to work on FreeBSD 4.8 STABLE.
*The above statement is false if I was too lazy to test it.*
Please take note that I am not a technical writer, nor do I care to become one.
If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
Don't assume that I'm ever entirely serious or entirely joking.
You could return an STL string. Those are much easier to work with anyway. You can do that like any other function:
Code:string my_func();
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
oh, and don't use void main.