In my project, I am asked to store my 2D array of words in a dynamic data structure, then use them in other functions for other purposes, but I am confused how should I do this. I do understand, how to name them separately like:
#include <stdio.h>
#include <stdlib.h>
typedef struct Names {
char *name[5];
} Names;
void func(Names y) {
printf("%s\n%s", y.name[0], y.name[1]);
}
int main()
{
Names y;
y.name[0] = "John";
y.name[1] = "Luke";
func(y);
return 0;
}
But what if I wanted to do this as a 2d array. So normally I would do char names[][10] = {"John", "Luke", etc..};
but how do I store that in a struct? I mean if I did
#include <stdio.h>
#include <stdlib.h>
typedef struct Names {
char *name[5][10];
} Names;
void func(Names y) {
printf("%s\n%s", y.name[0], y.name[1]);
}
int main()
{
Names y;
y.name[][10] = {"John", "Luke"};
func(y);
return 0;
}
That would just give errors and make no sense.