Showing posts with label display reverse content and save it in another file. Show all posts
Showing posts with label display reverse content and save it in another file. Show all posts

Thursday, August 13, 2009

display reverse content and save it in another file

/*reverse of file content display and stored in another file */
#include
main()
{
FILE *fp,*ft;
char c;
long int pos;
/*assume that a file ,conten.c and rev.c exit already*/
fp=fopen("conten.c","r");
ft=fopen("rev.c","w");
pos=ftell(fp);
/*printf("%ld",pos);*/
fseek(fp,-1,2);
while(ftell(fp)>pos)
{

c=fgetc(fp);
fseek(fp,-2,1);
fputc(c,ft);
printf("%c",c);
}
c=fgetc(fp);
printf("%c",c);
fputc(c,ft);
fclose(fp);
fclose(ft);

}