How to return pointer to array in c
<p>I call the function <code>getdata()</code> below inside main(). <code>getdata()</code> reads in characters from the uart and puts them in an array. At the end of the function it writes out the array over uart. </p>

<p>My question is, how can I get this function to return the data? I understand that you cannot return arrays in c and that you should declare a function returning a pointer. </p>

<p>How could I do that with the function below so that I can write out the data in main instead of having to do it inside <code>getdata()</code>. </p>

<pre><code>int main(void)
{
    getdata();
}

void getdata(void)
{
    static uint8_t ndx;
    char recChars[6];
    char retchar;
    ndx = 0;

    retchar = getch(); 
    recChars[ndx] = retchar;
    ndx++;

    if (retchar == '\r'){
        recChars[ndx] = '\n';
        ndx = 0;
        uart_write(UART_D, (uint8_t *)recChars, sizeof(recChars));
    }            
}

char getch(void) {
uint8_t ch = 0;
chuart_read(UART_D, &amp;ch);
return ((char) ch);
}
</code></pre>