# 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.