I have a for loop which is used to find the nearest helicopter to a specific ship in danger.
The problem I am having is I need to ignore LifeBoats from my search (these have the type of L
which is a single char in a struct) and only focus on Helicopters, represented by a H
which is a single char in a struct.
The problem I have is that when I have this for loop:
closest_index = 0;
for (j = 0; j < asset_size; j++) {
printf("type : %c \n", (assets + j)->type);
if ((assets + j)->type == 'H') {
if (((assets + j) ->distance_from_mayday) < ((assets + closest_index) ->distance_from_mayday)) {
closest_index = j;
printf("closest_index heli = %d \n", closest_index);
}
}
}
It definitely gets called, I added the line:
printf("type : %c \n", (assets + j)->type);
just before the comparison, and it produces this result in the console:
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : L
type : H
type : H
type : H
type : H
type : H
type : H
As you can see there is values of H
so I don't understand why this for loop is not executing as intented, any ideas?