i have a following funtion
uint8_t func(){
uint8_t key[16] = {0};
// some operations
return key;
}
i am calling this function in the main function
int main(void){
uint8_t rcKey[16] = func();
for (int i = 0; i < 16; i++)
{
printf("%x ", rcKey[i]);
}
}
what am i doing incorrectly here? I get invalid initializer error
An array can't be initialized directly via a function call. You can only initialize the individual elements as part of an initializer list.
What you can do instead is pass the array to a function to set the relevant values.
void func(uint8_t key[]){
// some operations
}
int main(void){
uint8_t rcKey[16]
func(rcKey);
for (int i = 0; i < 16; i++)
{
printf("%x ", rcKey[i]);
}
}