So I've got a program where I have to save a list of coordinate points into an array. I have to print the x and y coordinates of a specific point from the array but when I use %d it tells me it expects a type int.
The function index just finds the lower leftmost point in the array and returns its place in the array, and swap just swaps two points. Any advice here would be immensely appreciated!
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct point{ int x ; int y ;} POINT ;
int index( POINT *A ) ;
void swap( POINT x, POINT y ) ;
int main( int argc, char *argv[] ) {
int n, i, j ;
POINT *A[n-1] ;
FILE *fin ;
fin = fopen( argv[1], "r" ) ;
fscanf( fin, " %d ", &n) ;
A[n-1] = (POINT *) malloc( n * sizeof(POINT) ) ;
for ( i = 0; i < n; i++ ){ fscanf( fin, "%d %d", &A[i]->x, &A[i]->y ) ;}
j = index( A[n-1] ) ;
printf( "\n A[%d], (%d, %d)\n" j, A[j]->x, A[j]->y ) ;
swap( *A[j], *A[0] ) ;
for ( i = n; i >= 0; i-- ) {
printf( "\n(%d, %d)\n" A[i]->x, A[i]->y ) ;
}
fclose( fin ) ;
return 0 ;
}