#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *fd1;
FILE *fd2;
fd1=fopen("file1.txt","r");
fd2=fopen("file2.txt","w");
int *a=NULL;int *b=NULL;
int max=10;
a=(int *)malloc(max*sizeof(char));
int i=0,j=0;
while(fscanf(fd1,"%c",&a[i])!=EOF)
{
i++;
j++;
if(i>=max)
{
max=2*max;
b=(int *)realloc(a,max*sizeof(int));
a=b;
}
}
for(;--j>=0;)
{
fprintf(fd2,"%c",a[j]);
}
fprintf(fd2,"\n");
fclose(fd1);
fclose(fd2);
return 0;
}
#include<stdlib.h>
int main(void)
{
FILE *fd1;
FILE *fd2;
fd1=fopen("file1.txt","r");
fd2=fopen("file2.txt","w");
int *a=NULL;int *b=NULL;
int max=10;
a=(int *)malloc(max*sizeof(char));
int i=0,j=0;
while(fscanf(fd1,"%c",&a[i])!=EOF)
{
i++;
j++;
if(i>=max)
{
max=2*max;
b=(int *)realloc(a,max*sizeof(int));
a=b;
}
}
for(;--j>=0;)
{
fprintf(fd2,"%c",a[j]);
}
fprintf(fd2,"\n");
fclose(fd1);
fclose(fd2);
return 0;
}