how to return a string array from a function

后端 未结 9 693
暖寄归人
暖寄归人 2020-12-29 10:53
char * myFunction () {

    char sub_str[10][20]; 
    return sub_str;

} 

void main () {

    char *str;
    str = myFunction();

}

error:return

9条回答
  •  醉话见心
    2020-12-29 11:31

    first of all You can not return a string variable which is stored in stack you need use malloc to allocate memory dynamicaly here is given datails with the example Go https://nxtspace.blogspot.com/2018/09/return-array-of-string-and-taking-in-c.html get a proper answer

提交回复
热议问题