hello guys and gals.
I am taking a data file created by the program in another function which looks like this:These are all x y and z components of aircraft which the program creates in an early function (yes I did get it to work). Then I used a another function which looks like1 38 27
7 24 23
38 12 15
23 14 9
27 18 8
11 9 29
3 24 40
34 44 2
34 45 27
46 3 25
19 45 47
26 25 37
41 26 28
2 16 44
3 49 31
26 25 42
33 14 8
1 5 11
19 47 36
4 4 7
21 25 5
34 19 14
29 14 1
46 45 21
42 26 2
26 23 35
5 47 46
33 3 12
21 38 9
35 38 16
45 41 44
38 7 32
13 1 8
3 34 34
37 43 19
17 31 19
31 37 25
38 36 8
49 49 29
18 44 42
13 12 29
49 16 47
36 18 28
37 26 8
32 29 49
4 42 21
31 21 7
44 42 28
14 14 13
22 21 24
this function calculates all the aircrafts distances and writes them to a file. This works fine. But I created another function which will print to the screan the closet aircraft. How do I do this? Here are two of the many attempts at it: What have i done wrong?:Code:/*this is the function that will print to the distout.out file */ void FunctionDistout(FILE *Fplanes, FILE *Fdistout) { int aXaxis[50][3]; int i = 0; int j = 0; for(i=0; i<50; i++) { for(j=0; j<3; j++) { fscanf(Fplanes, "%d, %d %d", &aXaxis[i][0], &aXaxis[i][1], &aXaxis[i][2]); } } for(j=0; j<50; j++) { if(sqrt(aXaxis[j][0]*aXaxis[j][0]+aXaxis[j][1]*aXaxis[j][1]+aXaxis[j][2]*aXaxis[j][2]) < 55) { fprintf(Fdistout, "WARNING!!! Aircraft at %d %d %d is %3.2f KM away \n", aXaxis[j][0], aXaxis[j][1], aXaxis[j][2], sqrt(aXaxis[j][0]*aXaxis[j][0]+aXaxis[j][1]*aXaxis[j][1]+aXaxis[j][2]*aXaxis[j][2])); } } }
{
int aXaxis[50][3];
int i = 0;
int j = 0;
int l;
float u = 90;
for(i=0; i<50; i++)
{
for(j=0; j<3; j++)
{
fscanf(Fplanes, "%d, %d %d", &aXaxis[i][0], &aXaxis[i][1], &aXaxis[i][2]);
}
}
if(u > sqrt(aXaxis[j][0]*aXaxis[j][0]+aXaxis[j][1]*aXaxis[j][1]+aXaxis[j][2]*aXaxis[j][2]))
{
for(l=0; l<50; l++)
{
u = (sqrt(aXaxis[l][0]*aXaxis[l][0]+aXaxis[l][1]*aXaxis[l][1]+aXaxis[l][2]*aXaxis[l][2]));
}
}
printf("Nearest aircraft at %d %d %d: %f KM away.",
aXaxis[l][0], aXaxis[l][1], aXaxis[l][2], u);
}
void FunctionPrintSound(FILE *Fplanes)
{
int aXaxis[50][3];
int p = 0;
int q = 0;
int j = 0;
float u = 90;
for(p=0; p<50; p++)
{
fscanf(Fplanes, "%d, %d %d", &aXaxis[p][0], &aXaxis[p][1], &aXaxis[p][2]);
for(q=0; q<3; q++)
{
fscanf(Fplanes, "%d, %d %d", &aXaxis[q][0], &aXaxis[q][1], &aXaxis[q][2]);
}
}
for(j=0; j<50; j++)
{
if(u > sqrt(aXaxis[j][0]*aXaxis[j][0]+aXaxis[j][1]*aXaxis[j][1]+aXaxis[j][2]*aXaxis[j][2]))
{
u = (sqrt(aXaxis[j][0]*aXaxis[j][0]+aXaxis[j][1]*aXaxis[j][1]+aXaxis[j][2]*aXaxis[j][2]));
{
printf("Nearest aircraft at %d %d %d: %3.2f KM away.",
aXaxis[j][0], aXaxis[j][1], aXaxis[j][2], u);
}
}
}
}