How to show content of a text file in reverse direction in C language ?



This code will show file content in reverse direction :

 

#include<stdio.h>
#include<conio.h>

void main()
{
FILE *fp;
char c;
long counter=0;
clrscr();
printf(“Content of file in reverse direction : “);
fp=fopen(“c:/myfile.txt”,”r”); // file path and name
fseek(fp, -1L, 2);

counter = ftell(fp);
counter++;
while (counter)
{
c = fgetc(fp);

putchar(c);

fseek(fp, -2L, 1);

counter–;
}
fclose(fp);
getch();
}

 



Output of the code (if myfile content : Hello World):

 

Content of file in reverse direction : dlroW olleH

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.