struct test
{
unsigned int test1;
unsigned char test2[4096];
unsigned int test3;
} foo
struct foobar
{
unsigned char data[4096];
}
if i want to access the struct, i say foo.test1, foo.test2[4096], etc.. however, when I wish to return the data present in foo.test2 in the following manner
pac.datafoo = foo.test2[4096];
unsigned char data[4096] = pac.datafoo;
this is the error I get:
error: initialization with "{...}" expected for aggregate object
what is the mistake i'm doing?
You need to learn the array initialization method. It's NOT simply assigned as the single variable.
Some examples:
int arrayone[3] = {0}; // assign all items with 0
int arraytwo[3] = {1, 2, 3 }; // assign each item with 1, 2 and 3
int arraythree[3]; // assign arraythree with arraytwo
for (int i = 0; i < 3; ++i) {
arraythree[i] = arraytwo[i];
}
add ";" at the end of the struct.
struct test
{
unsigned int test1;
unsigned char test2[4096];
unsigned int test3;
} foo ;
struct foobar
{
unsigned char data[4096];
} ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With