When I want to initialize all the components of a struct I do it in the main function like this:
This is the struct:
typedef struct {
int data[1000];
int oc;
} Table;
And this is how I initialize all the components to be 0 (the array and the int now are 0 with this).
int main() {
Table x = {0};
Now I want to do exactly the same but using a function. I want to do something like this:
void initialize(Table *y) {
y = {0};
}
I think it does not work because to initialize it I should do it when I declare it, so how can I initialize a struct using a function?
structto a function if you are going to treat it as a local variable and overwrite whatever was in it.