Make the changes I've noted, and it should be close. This compiles with no errors in Turbo C.
Code:
#include<stdio.h>
#include<string.h> // for strlen() function.
#include<stdlib.h> // for exit() function.
int main()
{
int data[1024];
char sourcename[20];
char destinationname[20];
FILE *sFile,*dFile;
long t;
// char sourcename[20]; //<---Delete this line*********
printf("please input source filename");
gets(sourcename);
// char destinationname[20]; //<----Delete this line*****
printf("please input destination filename");
gets(destinationname);
if((sFile=fopen(sourcename,"rb"))==NULL)
{
printf("fail to open source file\n");
exit(0);
}
if((dFile=fopen(destinationname,"wb"))==NULL)
{
printf("fail to open destination file\n");
exit(0);
}
fseek(sFile,0L,SEEK_END);
t=ftell(sFile); //get the size of the file.
//#if 0
for(;(feof(sFile)!=0);)
{
fread(data,t,1,sFile);
printf("%s",sFile);
fwrite(data,t,1,dFile);
printf("%s",dFile);
}
//#else
/* you already have a read and write loop, just up above this.
You don't need another one. :)
while (1) {
fread(data,t,1,sFile);
fwrite(data,t,1,dFile);
if(feof(sFile)==0)
break;
}
#endif
}
*/
fclose(sFile);
fclose(dFile);
getch();
return 0;
}
The code in blue you already have, so you can get rid of it. Also, the lines of code with the stars and delete on them.