Saturday, November 22, 2014

file reverse copy using pointers

# include <stdio.h>

main()
{
FILE*f1,*f2;
char*str;
int sz,ch;
f1=fopen("c:\\a.txt","r");
f2=fopen("c:\\b.txt","w");

fseek(f1,0,SEEK_END);
sz=ftell(f1);
str=(char*)malloc(sz);
*(str+sz)=NULL;

fseek(f1,0,SEEK_SET);
while((ch=getc(f1))!=-1)
{
*(str+ --sz)=ch;
}

fputs(str,f2);
fclose(f1);
fclose(f2);
}

No comments:

Post a Comment