C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
concating many binary files into one file Posted by aarti_gehani on 19 Mar 2009 at 4:26 AM
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<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <string.h>

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??
Report
Re: concating many binary files into one file Posted by HK_MP5KPDW on 20 Mar 2009 at 10:21 AM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.