Hi,
Im trying 2 write the contents of a input file to an output file in reverse order using file I/O in C. Is there a more efficient way 2 do it?
int main()
{
FILE *fp1,*fp2;
char ch,arr[100];
int i=0;
if( (fp1 = fopen("input.txt","r")) == NULL )
{
printf("Not able to open file");
exit(1);
}
while((ch = fgetc( fp1 )) != EOF)
{
arr[i]=ch;
i++;
}
fclose(fp1);
fp2 = fopen("output.txt","w");
while( i>=0 )
{
fputc(arr[i], fp2);
i--;
}
fclose(fp2);
return 0;
}
Thanks.