binary file merging c++

March 17, 2010 at 01:12:44
Specs: Windows do
i want to merge two binary files. i would like to alternate between file 1 and file 2 taking a byte of data from each and writing the results to file 3. and repeating the alternating and writing to file 3 until end of file or no more data to read from file1 an file2.
for example:

file1 data
01 03 05 07 09 0B

file 2 data
02 04 06 08 0A FF

after alternating back and forth between file1 and file2 and writing to file3 and repeating till no more data is left in file1 and file2.

output should look like this;

file3 data
01 02 03 04 05 06 07 08 09 0A 0B FF

how would i do this or does this routine exist already somewhere. it doesnt matter what language or technique is used as long as I can get the combined result in file3 from taking alternating bytes of data from any two binary files i specify.


See More: binary file merging c++

Report •


#1
March 17, 2010 at 14:03:52
this is QBASIC version, also might port over to VisBasic if you use INPUTBOX and make it SUB MAIN() .
either way, it can be compiled into an executable.

DIM B AS STRING * 1
INPUT "INPUT FILE1: ",F1$
INPUT "INPUT FILE2: ",F2$
IF F1$+F2$="" THEN END
INPUT "OUTPUTFILE: ",FF$
IF FF$="" THEN FF$="CON"
OPEN F1$ FOR BINARY ACCESS READ AS #1
OPEN F2$ FOR BINARY ACCESS READ AS #2
OPEN FF$ FOR BINARY ACCESS WRITE AS #3
EO = 0
DO WHILE EO < 2
EO = 0
FOR i = 1 TO 2
GOSUB GETPUT
NEXT i
LOOP
CLOSE
END
STOP

GETPUT:
IF NOT EOF(i) THEN
GET #i, , B
PUT #3, , B
ELSE
EO = EO + 1
END IF
RETURN


Report •

#2
March 24, 2010 at 11:29:27
hi
i just wanted to say thank you. the program works exactly as i wanted. you are greatly appreciated. it has been very helpful and allowed me to verify and locate some extra needed information i otherwise had to do by manual changes. you have saved me hours of boring cut and pasting.

Report •

Related Solutions


Ask Question