I am not able to understand your problem clearly with the given data.
In the following code,


found_match = 0; //For this ID just given - mark that it has no match

// How would it keep...