Returning Arrays/Pointers from a function

前端 未结 7 1320
醉梦人生
醉梦人生 2020-11-28 12:07

I am trying to create a new integer array which is derived from a string of characters. For example :

char x[] = \"12334 23845 32084\";  

int y[] = { 12334,         


        
7条回答
  •  一个人的身影
    2020-11-28 12:53

    Typically, you require the caller to pass in the result array.

    void splitString( const char string[], int result[], int n) {
        //....
    }
    

    This is advantageous because the caller can allocate that memory wherever they want.

提交回复
热议问题