I have a program called interleave and it comes with an interleave.cpp file and I am trying to use this program to combine 2 files to result in 1 at regular intervals but I am not getting it. It does not open and does nothing when I click on it.
/*
interleave.cpp
Interleave two or more files
Build:
g++ -mno-cygwin -o interleave interleave.cpp
*/
/*
* Includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
/*
*
*/
int main(int argc, char *argv[])
{
if (argc < 3)
{
fprintf(stderr, "interleave\n");
fprintf(stderr, "Syntax: interleave file-out size file-in file-in...\n");
return -1;
}
FILE *fo = fopen(argv[1], "wb");
if (!fo) { fprintf(stderr, "Error opening output file!\n"); return 1; }
int bufsize = strtoul(argv[2],0,0);
unsigned char *buffer = new unsigned char[bufsize];
FILE *fi[32];
int files = 0;
for (int a=3; argv[a]; a++)
{
fi[files] = fopen(argv[a], "rb");
if (!fi[files]) { fprintf(stderr, "Error opening input file!\n"); return 1; }
files++;
}
int files_active = files;
for (int f=0; files_active; f++)
{
if (f == files) f = 0;
int read = 0;
if (fi[f])
{
read = fread(buffer, 1, bufsize, fi[f]);
if (read <= 0) { fclose(fi[f]); fi[f] = 0; files_active--; continue; }
fwrite(buffer, 1, read, fo);
}
//if (bufsize > read)
{
memset(buffer, 0, bufsize - read);
fwrite(buffer, 1, bufsize - read, fo);
}
}
fclose(fo);
delete [] buffer;
return 0;
}