Home Forums C Programming Reading and sorting records from a file

Viewing 1 reply thread
  • Author
    • #1956

      I have been trying to write code for reading and writing a file. I am facing a problem with that. I am using fread and fwrite functions for it. I am writing data through structures in a file. I want to make a simple telephone directory to which I can enter data, search a contact and list the contacts in alphabetical order.
      First of all I am writing records with fwrite function. Then I read it through fread function. What happens in this, when I open the file for reading purpose only, it repeats the last record twice in print or it shows junk values when I have given the contion to read upto EOF.
      Any good technique to handle file so I can enter data any time, read it, search it and sort the records. Please reply..msaqib39099.2203935185

    • #3219
      dham ampatuan

      If you’re doing it in a loop, probably you have forgotten to update the file pointer.
      use fseek (man fseek) for the same.

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.