I am trying to write a function to add two arrays. The catch is that the arrays have to parts of a structure. So here is what I have so far:
#include <stdio.h>
struct poly {
array1[];
array2[];
length;
};
void polyadd(int array1[],int array2[],int length) {
int i;
struct poly p;
for(i=0;i<length;i++) {
p.array1[i]=array1[i] + array2[i];
printf(" %d ", p.array1[i]);
}
}
int main(void) {
struct poly name1;
name1.length = 4;
name1.array1[4] = {3,0,7};
name1.array2[4] = {0,15,0,-4};
polyadd(name1.array1,name1.array2,name1.length);
return 0;
}
And here are the error messages I am getting:
structadd.c:4: error: expected specifier-qualifier-list before âarray1â
structadd.c: In function âpolyaddâ:
structadd.c:13: error: âstruct polyâ has no member named âarray1â
structadd.c:14: error: âstruct polyâ has no member named âarray1â
structadd.c: In function âmainâ:
structadd.c:20: error: âstruct polyâ has no member named âlengthâ
structadd.c:21: error: âstruct polyâ has no member named âarray1â
structadd.c:21: error: expected expression before â{â token
structadd.c:22: error: âstruct polyâ has no member named âarray2â
structadd.c:22: error: expected expression before â{â token
structadd.c:23: error: âstruct polyâ has no member named âarray1â
structadd.c:23: error: âstruct polyâ has no member named âarray2â
structadd.c:23: error: âstruct polyâ has no member named âlengthâ