- This topic has 1 reply, 2 voices, and was last updated 17 years, 7 months ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.
Home › Forums › C Programming › Reading and sorting records from a file
Hello,
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..
If you’re doing it in a loop, probably you have forgotten to update the file pointer.
use fseek (man fseek) for the same.