I was wondering if it was posible to declare an array of strings inside a function and return its pointer to main so as to keep working with the same array.
I already know how to send the pointer to an array to a function so I can work with the same array inside it, but I'm having trouble reversing this process. I tried several things but it doesn't seem to work and honestly I don't even know where to begin. I would appreciate it if someone could explain me what I am getting wrong because obviously I have no idea what I'm doing. This code was written in C, but I believe it would be the same or very similar for C++.
#include <stdio.h>
#define Y 8
char *ini();
int main() {
//I have no idea what I'm doing
char *chP= ini();
char planets[Y][10] = chP;
//Just for printing the array
for(int i = 0;i<Y;i++){
printf("\n%s", planets + i);
}
return 0;
}
char *ini() {
char *chP;
char planets[Y][10] = {
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Saturn",
"Uranus",
"Neptune"
};
chP = planets;
return chP;
}