I’ve declared an array of structs as so:
typedef struct{
int source;
int dest;
int type;
int port;
char data;
}test;
test packet[50];
and I’m trying to access the array and print it to the screen as such:
for (p = 0; p < i; p++)
{
printf("%i", packet[p]);
}
But I’m not getting what I expect. I’m very new at C so I’m sorry for any problems with this post. Just ask for more information and I’ll give it. Have I got the logic completely wrong with this?
In my head I’ve created an 50 instances of the struct in an array with each element of the array containing the 5 variables in the struct.
It’s been ages since I’ve done C but I don’t think it works that way. You might want to print the struct’s member variables one by one.
Or better yet, make a method, call it something like
printTest()and have it do the above.In your example above, you’re trying to print the whole object, which wouldn’t work.