How can I correctly return an array from a function in C and assign its value to a pointer