I need to calculate the distance between two points, but when I call the function that does this (calculates the distance), it gives the error: "subscripted value is neither array nor pointer nor vector".
I did the same thing in another function. I had to calculate the distance between two points and it worked. I do not know why it does not work now.
Distance function:
float distancia(int ax, int ay, int bx, int by)
{
return (sqrt((pow((ax - bx), 2)) + (pow((ay - by), 2))));
}
Function where it worked when I called 'distance':
void mDistancia(char cidadeXY[][150], int coordenadasX[], int coordenadasY[], float matrizDistancia[][30])
{
int c, i, contadorC, contadorI;
float dij;
for(i = 0, contadorI = 0; i < 30; i++, contadorI += 2)
{
for(c = 0, contadorC = 0; c < 30; c++, contadorC += 2)
{
dij = distancia(coordenadasX[contadorI], coordenadasY[contadorI], coordenadasX[contadorC], coordenadasY[contadorC]);
matrizDistancia[i][c] = dij;
}
}
}
Function where it did not work:
void problema5(char cidadeXY[][150], int coordenadasX[], int coordenadasY[])
{
int i, j;
float distanciaX, distanciaY;
float dis, aux;
int cX, cY;
char cid[150];
for(j = 0; j < 30; j++)
{
aux = distancia(coordenadasX[j], cX[j], coordenadasY[j], cY[j]);
if(aux < dis)
{
dis = aux;
strcpy(cid, cidadeXY[i]);
}
}
}
Notice that I did the same thing. I stored the returned value in the aux float variable, just as I did with the variable float dij. But it only gives this error in function problem5. The error occurs twice, more specifically in j in coordinates Y [j] and cX [j]. At least that's what it says in the terminal.