c programme to avoid duplicate data when read file thru file handling

Hi All,

I want to get some values by reading a file (already created) through file handeling but dont want to get DUPLICATE values.

How can i do that..plz help me out.......

E.g: file name input.txt having rows like:

Root 400
Bye 789
Teacher 123
Bye 789

in output i want to print only :
Root 400
Bye 789
Teacher 123

Note: Dont want to print duplicate data (Teacher 123)

If any idea..plz tell me ...with example too.



  • You have to store the data you read in some sort of list. If you are writing in C++ you have the STL containers "set", "map" etc. Otherwise you will have to create the container yourself. If you want the container to have quick inserts and search functionality (ie if the amount of data is large) you should consider binary trees, hash tables etc.

    If speed isn't important, you could simply store all the elements in an array and iterate through them, checking every entry with strcmp().
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion