How do I return an string from a function.
VB:
Code:
void main {
Char str[];
str=getstr():
printf("%s",str);
}
getstr() {
string="I work";
}
Printable View
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);
}
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();
oh, and don't use void main.