It is impossible to know that a fruit is not in the file until you have read the entire file. NetWallah has proposed a program that saves (but does not print) the required data as you read the file. After all the data is collected, you can decide what to print.