I have a list. Each element of the list is a struct.
struct A
{
int size;
}
The data looks like:
list[0]->size = a number.
How can I assign a pointer to each member of the list?
int *p;
for(i = 0; i < listSize; i++)
{
p = &list[i];
}
That won't work since I am assigning only one pointer to the last element of the list. Should I make a list of pointers?
This should solve the XY problem. How do I create pointers for every element of my list?
EDIT: List looks like this
A **list;
I want to sort by pointers instead of by structures so that it is faster.
Trying this now:
A ***p = (A***) malloc(sizeof(A***));
for(i = 0; i < listLength; i++)
p[i] = &list[i];
for(i = 0; i < listLength; i++)
printf( p[i]->size); // Error.