Home › Forums › C Programming › Reading and sorting records from a file
- This topic has 1 reply, 2 voices, and was last updated 13 years, 8 months ago by
dham ampatuan.
- AuthorPosts
- December 26, 2006 at 8:23 pm #1956
grishma
ParticipantHello,
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..msaqib 39099.2203935185 - May 21, 2007 at 12:16 am #3219
dham ampatuan
ParticipantIf you’re doing it in a loop, probably you have forgotten to update the file pointer.
use fseek (man fseek) for the same.
- AuthorPosts
- You must be logged in to reply to this topic.