# Thread: Finding lowest value

1. ## Finding lowest value

hello guys and gals.

I am taking a data file created by the program in another function which looks like this:
1 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
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 like
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]));
}
}

}```
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?:

{
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);
}

}

}
}

2. btw Both of these functions work, but do not return the correct results

3. Originally Posted by sloopy
btw Both of these functions work, but do not return the correct results
They probably hurt themselves trying to read unindented code. On an aside, I don't consider 'do not return the correct results' to be code that 'works'.

Eh...alright, but this is the last time I read your code until you learn how to indent.
Code:
``` 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]);
}
}```
Why do you have a loop that reads 3 lines, each of which read 3 items, inside a loop that executes 50 times. Do you have 150 lines in your file? Oh, also, stop using & there. You don't need to with arrays of basic types.
[/edit]

Quzah.

4. > Oh, also, stop using & there. You don't need to with arrays of basic types.
The arrays make no difference, it's still %d in the conversion, so it still needs to be a pointer to an int.

5. they were indented

6. Indenting only works with code tags, not quote tags.
I only fixed one set of tags, in the (vain) hope that you would click 'edit' and fix the others yourself.
Oh well.

Popular pages Recent additions