I am having trouble iterating through a 2D array when the array is being called through the parameters of a function.
The problem is that when being run directly in main it can print out the array perfectly, but when called from func() it outputs an empty result.
2D array called from parameters:
void func(char *arr[]) {
for (int i = 0; i < 3; i++) {
printf("%s", arr[i]);
}
}
int main() {
char arr[3][5] = {"B10","A12", "D21"};
func(arr);
return 0;
}
2D array being iterated directly:
int main() {
char arr[3][5] = {"B10","A12", "D21"};
for (int i = 0; i < 3; i++){
printf("%s", arr[i]);
}
return 0;
}
Expected output for both: B10A12D21