concating many binary files into one file - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

concating many binary files into one file

aarti_gehaniaarti_gehani Posts: 15Member
i have the following codes for concating many binary files into single file.but it is showing some error which i am not able to understand.

#include
#include
#include
#include

int main()
{


FILE *fs,*ft1,*ft2,*ft3,*ft4,*ft5,*ft6,*ft7,*ft8,*ft9,*ft10,*ft11;
char c;
long i,Filesize;


fs=fopen("newfit_1.fit","wb");

i=0;
do{
ft1=fopen("newaarti1.fit","rb");
fseek(ft1,0,SEEK_END);
Filesize=ftell(ft1)-1;
c=getc(ft1);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft1);

i=0;
do{
ft2=fopen("newaarti2.fit","rb");
fseek(ft2,0,SEEK_END);
Filesize=ftell(ft2)-1;
c=getc(ft2);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft2);

i=0;
do{
ft3=fopen("newaarti3.fit","rb");
fseek(ft1,0,SEEK_END);
Filesize=ftell(ft3)-1;
c=getc(ft3);
i=i+1;
fputc(c,fs);
}
while(i<=Filesize);
fclose(ft3);

i=0;
do{
ft4=fopen("newaarti4.fit","rb");
fseek(ft4,0,SEEK_END);
Filesize=ftell(ft4)-1;
c=getc(ft4);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft4);

i=0;
do{
ft5=fopen("newaarti5.fit","rb");
fseek(ft5,0,SEEK_END);
Filesize=ftell(ft5)-1;
c=getc(ft5);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft5);

i=0;
do{
ft6=fopen("newaarti6.fit","rb");
fseek(ft6,0,SEEK_END);
Filesize=ftell(ft6)-1;
c=getc(ft6);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft6);

i=0;
do{
ft7=fopen("newaarti7.fit","rb");
fseek(ft7,0,SEEK_END);
Filesize=ftell(ft7)-1;
c=getc(ft7);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft7);

i=0;
do{
ft8=fopen("newaarti8.fit","rb");
fseek(ft8,0,SEEK_END);
Filesize=ftell(ft8)-1;
c=getc(ft8);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft8);

i=0;
do{
ft9=fopen("newaarti9.fit","rb");
fseek(ft9,0,SEEK_END);
Filesize=ftell(ft9)-1;
c=getc(ft9);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft9);

i=0;
do{
ft10=fopen("newaarti10.fit","rb");
fseek(ft10,0,SEEK_END);
Filesize=ftell(ft10)-1;
c=getc(ft10);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft10);

i=0;
do{
ft11=fopen("newaarti11.fit","rb");
fseek(ft11,0,SEEK_END);
Filesize=ftell(ft11)-1;
c=getc(ft11);
i=i+1;
fputc(c,fs);

}
while(i<=Filesize);
fclose(ft11);
fclose(fs);

getch();
return 0;
}

i wish to read the binary files till one minus from their filesize.so i have used filesize as variable which contains the required size of the file.

can anyone plz help me for the same?
is it possible to make a function which calculates the size of the file and can i call that function each time time i require in main??

Comments

  • HK_MP5KPDWHK_MP5KPDW Posts: 770Member ✭✭✭
    First off, you should use code tags whenever posting code samples.

    :i have the following codes for concating many binary files into single file.but it is showing some error which i am not able to understand.

    What error is it showing?



    :is it possible to make a function which calculates the size of the file and can i call that function each time time i require in main??

    There's a lot of duplicated code, I'd make a function that does the reading and writing and just call that individually for each file. That should reduce the amount of code significantly. You can open the write file in main and pass the pointer to that file along with a filename to this function. The function could then open the file indicated by the filename and go through the reading/writing and all of that.
Sign In or Register to comment.