Reading data from files

I have a list of files, 4 files for example
Then I have two buffers ifa and ifb giving me the file numbers
from which I need to get a group of data. For example, the first
four groups use file 1. The fifth group uses data from file 1 and
file 2.

I am thinking of storing all the data in the file to a buffer called
blk. So I just open the file, read each record and put it in blk.
So for groups 1 to 5, I get the group data from blk. For the fifth group
I also need to get the data from file 2. Thus I am thinking of having
two blocks, blka and blkb that store two files.

I have put something in fortran, however c will do. I would be grateful to get some help constructing the code to do this.

 
fls(4) = [fname1,fname2,fname3,fname4]
 
ifla(1:ngrps) = [1,1,1,1,1,2,2,3,3,3,4,4]
iflb(1:ngrps) = [1,1,1,1,2,2,2,3,3,4,4,4]
do igrp = 1, ngrps
  open file ifla(igrp)
  do irec = 1, nrec
    read file(ifla(igrp)) rec(irec)
    store in blk
  enddo
  fill group from blk
enddo

1) It can be hard to work from theoretical (your description). Perhaps paste into a message a small section of each of the files and what you are desiring for output.
2) What have you tired to accomplish your request? The Forum is here to assist, but not necessarily write complete code.