Working with files in C

A

asn

Example :
If i store details of Employee no and name in a text file and the
employee salaries in another.
Is it possible to read data from these two files simultaneously using
file stream concepts?
If so, can anyone help me with an example.
 
K

kernelxu

asn says:
Is it possible to read data from these two files simultaneously using
file stream concepts?
what do you mean by "simultaneously using file stream concepts"?
 
M

Michael Mair

asn said:
Example :
If i store details of Employee no and name in a text file and the
employee salaries in another.
Is it possible to read data from these two files simultaneously using
file stream concepts?

Depends on your concept of simultaneously.
You can open two streams and read alternately from both as needed.

If so, can anyone help me with an example.

This sounds like a homework question, so: sorry, I won't.

Bring your best shot at the solution, tell us what problems you
have with it. Then you will get help.


Cheers
Michael
 
S

SM Ryan

# Example :
# If i store details of Employee no and name in a text file and the
# employee salaries in another.
# Is it possible to read data from these two files simultaneously using
# file stream concepts?
# If so, can anyone help me with an example.

You can have some number of simultaneously open files. I've seen
minimums of 20 and maximums of tens of thousands, depending on the
system. Each open file maintains its own file position; on a seekable
device (disk files are seekable on all rational systems) you can
move forward and backwards with fseek and related functions.

So, yes, you can read a primary file line by line, parsing the line
into fields. Then as you read and parse that file, you can position
the secondary file and join to the line with the matching key, reading
and parsing that line.

You can position the second by rewinding and then reading each line
up to the match. Or if you have additional information about, such
as it is always sorted on its search key, you can search it more
efficiently. You can also scan the file once on open and use ftell
or fgetpos to build up and internal index of the file. Subsequently
you can fseek or fsetpos directly to the line with the key.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top