Hi guys!
I'm having a problem using a struct I defined as a function parameter. The error is probably quite basic, but I haven't been able to solve it. The code is something like
Code:
typedef struct menuOps {
int num;
char *string[];
} menuOPS;
// Is it ok to declare a menuOPS object like this?
menuOPS opsplash = {3, { "string1" , "string2" , "string3" } };
void menu(void (*menufunc)(void), menuOPS ops) {
int i;
menufunc(); // don't mind the first parameter, just a function pointer that prints stuff. Everything working here
for(i=0;i<=ops.num;i++)
printf(" %d - %s\n",i+1,ops.string[i]);
}
void main() {
printf("%s\n",opsplash.string[0]); // printfs' fine, "string1"
getchar();
menu(&menu_splash,opsplash);
getchar();
}
The problem is when menu() prints opsplash.string[i], when all I get is gibberish. It prints stuff like
Code:
1 - [??
2 - ????
3 - [????O
4 - ????
Can't say it is random trash, because it's exactly the same set of characters everytime I run it.
Thanks in advance for the help!