main() below calls getdata() which reads characters continously from the uart in a do while loop. 
It puts them in an array an when the array is full it writes them out over uart.
How can I get this to just fill the array once and return it to main() and I can write it out in main()?
 int main(void)
 { 
 getdata();
//How can I return the array once to main and write it out over uart()? 
}
void getdata(void)
{
static uint8_t detected = 0;
static uint8_t ndx;
char receiveddata[6];
    char retchar;
do{
    retdata = getch(); //read char from the uart
    if ((retdata == 'Z') && (detected == 0))
    {
        detected = 1;
        ndx = 0;
    }
    if ((detected == 1) && (ndx < 5))
    {
        receiveddata[ndx] = retdata;
        ndx++;
    }
    if (retdata == '\r'){
        receiveddata[ndx] = '\n';
        ndx = 0;
        detected = 0;
        uart_write_buffer(UART_4, (uint8_t *)receiveddata, sizeof(receiveddata));
    }
}while(1);
}
 
     
    