With an input of an integer 4, for example, I'm trying to get the following output w/ the initializePoly function. (0, 0) (-1, 1) (-2, 4) (-3, 9)
Instead, I'm getting all 0s in the outputs' second value when I run the code. Any feedback much appreciated.
#include <stdio.h>
#include <stdlib.h>
struct point{
int x;
int y;
};
void printPoint(struct point);
void printPoly(struct point *, int);
void initializePoly(struct point *, int);
int main(void) {
// Fill in your main function here
struct point * polygon;
int num;
scanf("%d", &num);
polygon = (struct point *) malloc(num * sizeof(struct point));
initializePoly(polygon, num);
printPoly(polygon, num);
free(polygon);
}
void printPoint(struct point pt) {
printf("(%d, %d)\n", pt.x, pt.y);
}
void printPoly(struct point *ptr, int N) {
int i;
for (i=0; i<N; i++) {
printPoint(ptr[i]);
}
}
// Write your initializePoly() function here
void initializePoly(struct point *pt, int num){
int i;
for(i=0;i<num;i++)
pt[i].x = -i;
pt[i].y = i*i;
}