I keep getting a crash in the case 4 of my switch in my main function and cant fix it.
I will explain the code a bit and hope you guys can help me:
Initializing the function
void function1(char[]);
Declaring the array of strings
const char *my_array[] = {
"Array of strings one",
"Array of strings two",
"Array of strings three"};
Looping through the array of strings in the main function (This works correctly, it prints the array of strings)
int i;
for (i=0; i < 3; i++) {
printf("%s\n", my_array[i]);
}
The code in the switch function (still in the main function)
case 4:
function1(my_array);
break;
I've tested and all of the previous code works correctly, the problem is in here (outside the main function):
void function1(char my_array[]) {
for (i=0; i < 3; i++) {
printf("%s\n", my_array[i]);
}
printf("\n");}
When I execute the case 4 of the switch, it crashes.
The 2 warning the log gives:
warning: passing argument 1 of 'function1' from incompatible pointer type
warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
Sorry if the explanation its a bit unclear I tried as hard as I could for it to be easy to understand.
I really hope you guys can help me, thanks!!
char [], you're passing achar *[]orchar **