help needed with my programe
i wrote a programe that suppose to read 3 coloms and 20 row into an array and split them into 3 different arrays one array for taxi status(1=available 2=inuse,3=oncall) 2nd one for x-coordenat of taxi and the 3rd one for y-coordenat of the taxi the programe should determin the state of the taxi from taxistate array and if that is available taxi the programe should calculate the distance between the taxi location and (Xc,Yc) which is the location of the customer needing a taxi. the programe should write all the distance between the the cstomer and the available taxis into the array d_distance and write all the distance between the in use taxis and the customer into array called d_inuse and do the same form in call taxi
---------------
the programe give no error when compiled but when i tried to print to the screen the array that contain the distance between customer and available taxis or even one element from that array my programe clashes and i got small window saying Access Violation and gives me choise of save details and close ????? i have never seen that windows before
------------------
here is my code
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define NROWS 20
#define NCOLS 3
#define STATECOL 0
#define XCOL 1
#define YCOL 2
main()
{
FILE *inputdata;
int i,j,xc,yc,tc;
int taxi_list[NROWS][NCOLS];
int taxistates[20],xtaxi[20],ytaxi[20];
int d_available[20],d_inuse[20],d_oncall[20];
// customer info.
printf(" please note that u need to press enter after entering any inputs \n Enter your location as X and Y coordenate:\n");
printf("Enter your X-coordenate \n X=");
scanf("%d",&xc);
printf("Enter your Y-coordenate \n Y=");
scanf("%d",&yc);
printf("after how many mins you need the taxi ");
scanf("%d",&tc);
//open input file to read
inputdata=fopen("taxis_info.txt","r");
if (inputdata==NULL){
printf("error canot open taxis_info \n");
exit(1);
}
//read all info from input file to one array
for (i=0;i<NROWS;i++){
for(j=0;j<NCOLS;j++){
fscanf(inputdata,"%d",&taxi_list[i][j]);
}
}
// creat 3 different arrays from the previous 20x3 array
//for taxistates,x-coord, y-coord of the taxis
for ( i = 0 ; i < NROWS ; i++ ) {
taxistates[i] = taxi_list[i][STATECOL];
xtaxi[i] = taxi_list[i][XCOL];
ytaxi[i] = taxi_list[i][YCOL];
}
//craet 3 arrays to hold distance from customer to available,inuse and oncall taxis
//initialise the three arrays with zeros
for(i=0;i<NROWS;i++){
d_available[i]=0;
d_inuse[i]=0 ;
d_oncall[i]=0 ;
}
//check taxistates f (ie available,inuse,oncall or not available taxis)
//calculate distance between customer and each available,inuse and oncall taxi
//place each set of distances in an array
for (i=0;i<NROWS;i++){
if (taxistates[i]==1)
d_available[i]=sqrt((xc-xtaxi[i])^2+(yc-ytaxi[i])^2);
else if (taxistates[i]==2)
d_inuse[i]=sqrt((xc-xtaxi[i])^2+(yc-ytaxi[i])^2) ;
else if (taxistates[i]==3)
d_oncall[i]=sqrt((xc-xtaxi[i])^2+(yc-ytaxi[i])^2);
}
//testing element in the array
printf("%d",d_available[5]);
}
-----------------
here is my input file
1 0 1
1 0 2
1 1 0
1 2 0
1 1 1
1 1 2
1 2 1
2 2 2
2 1 3
2 3 1
2 3 0
2 3 2
2 2 3
3 4 1
3 4 2
3 4 5
0 3 3
0 3 3
0 3 3
could any1 plz help me as the diedline for the assignment in 2 days