Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from a variable length file

Status
Not open for further replies.

cbeganesh

Programmer
Aug 3, 2005
5
US
does anybody have any examples of reading from a variable length file using fread, Im using something like this
fread(&sInputRec, Len,1, fpInput);
but the problem is i dont know the length for each record.
Thanks
 
Surely there must be some way of detecting the length of each record. A length prefix maybe? A record terminator?


Trojan.
 
Put another way, if you don't know the length, how are you going to process the data?


--
 
I'm assuming that the records ahve some sort of delimiter
Option 1
Read the whole file into a buffer. i.e.
stat the file
malloc of enogh memory
read in the file
use something like strtok to break up the file into records.

Option 2
Create a buffer big enough to handle the biggest record. Read in the file byte at a time int the buffer until the delimiter is met.

The exact implementation is left as an excercise!

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top