I am working on using a structure in a function, but when I try to run the code I get this error:
note: expected 'pixels_t' {aka 'struct '} but argument is of type 'pixels_t *' {aka 'struct *'}
Here is my code:
typedef struct{
unsigned int a, b, c;
}letters_t;
void fillLetterArray(letters_t letters);
int main (void){
letters_t letterArray[100];
fillLetterArray(letterArray);
}
void fillLetterArray(letters_t letters){
}
Thank you in advance for the answer.
CodePudding user response:
Your function takes structure, but your main program wants to pass pointer to the structure. You need to change this function accordingly:
void fillLetterArray(letters_t *letters);
int main (void)
{
letters_t letterArray[100];
fillLetterArray(letterArray);
}
void fillLetterArray(letters_t *letters)
{
}
CodePudding user response:
I suggest you abstain from (ab)using typedef
without a good reason, it's meant to create abstractions, and there's no advantage in this context.
If the intention is to fill an array, as the name implies, then the function fillLetterArray
needs to take a pointer to the array; additionally, it's a good idea to include the length of the array in a parameter:
#include <stdint.h> // for size_t
struct letters {
unsigned int a, b, c;
};
static void fillLetterArray(struct letters *letters, size_t length);
int main (void) {
struct letters_t letterArray[100];
fillLetterArray(letterArray, 100);
}
void fillLetterArray(struct letters *letters, size_t length) {
...
}