I'm using a library that has a typedef struct that contains a few variables and an array. I'm trying to pass a pointer to a variable of this type to another function and assign values into the array.
//typedef in library file
typedef struct
{
int a;
int b;
int arr[5];
} MyType;
... This is in another file
void foo()
{
MyType newtype;
//...lots of code
setArray( &newtype );
return;
}
void setArray ( MyType* mytype )
{
mytype->arr = {
1,2,3,4,5,
};
return;
}
When I try to compile this code I get the following error on the line with
mytpe->arr = {
Expected expression before '{' token
I've tried it a few different ways such as mytype->arr[5] = { but I get various syntax errors.
I'm new to C but I understand that an array really acts as a pointer to the first element in the array. Is what I'm trying to do not possible and I need to loop through the indices of each array and assign them one at a time?
mytype->arr[0] = 1; mytype->arr[1] = 2; ...arrhas no type? Looks weird.