I'm trying to pass an array of pointers to structure as parameter, to modify it in a function and to to print the modified value in main().
The code is:
#include "stdio.h"
typedef struct testStruct_s {
int x;
int y;
} testStruct;
typedef testStruct typeTab[4];
void modify(typeTab tab)
{
printf("Before modification %d\n", tab[2].x);
tab[2].x = 3;
printf("Modified %d\n", tab[2].x);
}
int main()
{
typeTab tab[4];
tab[2]->x = 0;
printf("First %d\n", tab[2]->x);
modify(*tab);
printf("Second %d\n", tab[2]->x);
return 0;
}
And I got the following output:
First 0
Before modification 1719752944
Modify 3
Second 0
I don't know the way to get the correct value of tab[2].x in modify() and how to modify this value to print tab[2]->x = 3 after.
For what I try to do, it is required to use the typedef testStruct.