Vote count:
0
In order to fill a structure with integers (to then be passed on further in the program) I thought the following would work:
main() {
struct songs {int pitch[5], length[5];} songs[4];
int i[5]={1,22,23,14,52};
int k=0;
songs[0].pitch=i;
for (k=0; k<5; k++) printf("%d\n",songs[0].pitch[k]);
}
however this comes up with an error "incompatible types in assignment"
if I dont however pass this array to the structure, using the following:
main() {
int i[5]={1,22,23,14,52};
int k=0;
for (k=0; k<5; k++) printf("%d\n",i[k]);
}
it compiles and will display the content of the array.
I realise there is probably a simple fix to this, but any help would be brilliant!
Thanks in advance
asked 13 secs ago
Passing an Array to a structure in C
Aucun commentaire:
Enregistrer un commentaire