I have a homework that wants us to make an array of (x,y) coordinates that the user enters but we don't know how many will be entered, it will end when (0,0) is entered, the last one will not be added to the array and then we sort them and print them.So I used pointers to make array but I can't insert all the elements that I want to insert it only recognizes the last entered one. When I try to print them it will print only the last one I entered correctly the others mostly comes (0,0) or some random numbers.
int main()
{
int x,y,*xp,*yp;
int a = 0,s,m=12;
etiket:
scanf("%d %d",&x,&y);
printf("\n");
while (x != 0 || y != 0)
{
a=a+1;
xp = (int*) malloc(sizeof(int)*m);
yp = (int*) malloc(sizeof(int)*m);
//printf("%d %d\n",x,y);
if( a%10==0)
{
xp = (int*) realloc(xp,sizeof(int)*m+10);
yp = (int*) realloc(yp,sizeof(int)*m+10);
}
xp[a]=x;
yp[a]=y;
printf("%d %d\n",*(xp+a),*(yp+a));
goto etiket;
//SortPoints((xp+a),(yp+a),a);
}
//printf("siralama:\n");
//for(s=0; s<=a; s++)
//{
// printf("%d %d\n",*(xp+s),*(yp+s));
//}
}
So this is my work-in-progress code. I don't even know if it's possible I would appreciate any help. Thank you in advance.