c - Can someone help me with pointers -


struct complex{     int x;      int y; };  void add(struct complex *b[]);  int main(int argc, char** argv) {      struct complex a[3];     struct complex *ptr[] = { &a[0] , &a[1] , &a[2] };      printf("indtast a->x = ");     scanf("%d", a[0].x);     printf("indtast a->y = ");     scanf("%d", a[0].y);     printf("indtast a2->x = ");     scanf("%d", a[1].x);     printf("indtast a2->y = ");     scanf("%d", a[1].y);     printf("indtast a3->x = ");     scanf("%d", a[2].x);     printf("indtast a3->y = ");     scanf("%d", a[2].y);      add(ptr);      return 0; }  void add(struct complex *b[]){      printf("%d + i%d",b[0].x + b[1].x + b[2].x, b[0].y + b[1].y + b[2].y);  } 

im trying point array of structure til function, print calculated complex number. gives me error. can please help? in advance

you forgot add "&" operator in scanf

try this

 struct complex{  int x;   int y;  };   void add(struct complex *b[]);   int main(int argc, char** argv) {   struct complex a[3];  struct complex *ptr[] = { &a[0] , &a[1] , &a[2] };   printf("indtast a->x = ");  scanf("%d", &a[0].x);  printf("indtast a->y = ");  scanf("%d", &a[0].y);  printf("indtast a2->x = ");  scanf("%d", &a[1].x);  printf("indtast a2->y = ");  scanf("%d", &a[1].y);  printf("indtast a3->x = ");  scanf("%d", &a[2].x);  printf("indtast a3->y = ");  scanf("%d", &a[2].y);   add(ptr);   return 0;  }   void add(struct complex *b[]){   printf("%d + i%d",b[0].x + b[1].x + b[2].x, b[0].y + b[1].y + b[2].y);   } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -