I have to make a function that creates points in the structure Points, I can get it to work if i manually add the points but when I try to make it so the user can add points then it stops working.
This appear every time I try to run my code:
n function ‘PrintPoint’:
error: subscripted value is neither array nor pointer nor vector
printf("Point %d is in (%f,%f)\n", i, p[i].X, p[i].Y);
^
In function ‘createPoint’:
error: variable-sized object may not be initialized
struct Point p[i] = {x, y};
^~~~~
This is my code:
/* a) creates the data structure */
struct Point {
float X;
float Y;
}p;
typedef struct Point points;
int main() {
printf("This program will create an array and do all the points\n"); //What it does
double x, y;
int cant;
/* c) create points */
printf("Please insert the amount of points you wish to create\n");
scanf("%d", &cant);
struct Point p[cant];
for (int i = 3; i < cant; i++){
printf("X and Y\n");
scanf("%d %d", &x, &y);
points* createPoint(x, y, cant, i);
}
/* b) prints the points */
PrintPoint(p);
/* c) creates point function */
return 0;
}
void PrintPoint (points p, int cant){
for (int i = 0; i < cant; i++){
printf("Point %d is in (%f,%f)\n", i, p[i].X, p[i].Y);
}
}
points* createPoint (double x, double y, int cant, int i){
struct Point p1 = {2.0, -3.0};
struct Point p2 = {-4.0, 5.0};
struct Point p[i] = {x, y};
}