libsndfile-mixing any number of soundfiles in loop

I am very new in programming (six months), so many apologies for silly questions.
I intended to write a console prog that uses libsndfile. It is kind of synthetiser. It reads text file created by user, where on each line, the information about parametres of sound synthesis are stored (frequency, amplitude, FM, AM, Additive, envelopes, effects...). For each line there is an corresponding process loop, that counts and performs synthesis and in the end creates *.wav soundfile. So in the end of main loop there are as many soundfiles as number of lines in the text file. These sound files may differ in lenth, but not in number of channels and samplerate, there are given names by the number of line in text file, that represents their data (i.e.: 0.wav, 1.wav, 2.wav – for textfile of three lines). This works perfectly...everythink is created and closed, there are no warnings during compilation, console does not fail. – But now should come the easy stuf. I need to mix all the files into one final output file. I want to create an loop taking these temporary files and writing them into the output file in line (witing one after another to the end of output file). I have tryed to do this in several ways, but I am probably not using the sf_seek function correctly, as the files are just rewriting themself...or there is somethink bad with my way of memory managemant. Please can you support me with any idea, what I am doing wrong? Or better, write an example code how to write one *.wav file to the end of another? I am very fresh in c++.

than delete all temporary files...and end the code
_________________________________________
I know that I am mixing C with C++, but seems to me, that it is not the problem.
Integer n in for loop is the number of files plus 1. <def_len> in the code has value of 1024.