Passing array of structures by pointer
Hi there, I have been trying to write a simple program to pass an array of structures via pointer. I'm sorry if this is a trivial question, and I'm sure it has been asked many times before. I have looked on google, however haven't managed to find exactly what may be wrong with my code. Any help would be much appreciated, thanks, Ed
p.s. I have tried allocating memory using malloc but got even more compile errors..
Code:
//Structure Passing example
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int w;
int h;
} card_t; //card_t is declared to be of type struct
//prototypes
void assign(void);
card_t *(card_table)[20]; //card_table is a pointer to an array of card_t structures
void assign()
{
int w=3;
card_table[0].w = w;
}
int main(void)
{
assign();
int temp = card_table[0].w;
printf("%d",temp);
return 0;
}
Compile error: "request for member 'w' in something not a structure or union"