0
I have a program called Interleave and it comes accompanied by a file Interleave.cpp and I’m trying to use this program to combine 2 files to result in 1 at regular intervals, but I’m not getting it. It doesn’t 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;
}
How will someone respond without seeing code, not knowing the format of the files to be combined... crystal ball does not work no
– epx
This is the cpp file of the progamma.
– Pedro
put the code below
– Pedro
@Pedro to add more information to the question, simply edit. Do not use the response field. Please remove that response and do the [tour] to learn how the community.
– NoobSaibot