28. write a C Program to display the file content on reverse order


Program to display the file content on reverse order

Source Code:

#include<stdio.h>
int main()
{
      FILE *fp;
      char ch;
      int i,pos;
      fp=fopen("/home/smec/Desktop/hello.txt","r");
      if(fp==NULL)
      {
            printf("File does not exist..");
      }
      fseek(fp,0,SEEK_END);
      pos=ftell(fp);
         i=0;
      while(i<pos)
       {
            i++;
            fseek(fp,-i,SEEK_END);
            ch=fgetc(fp);
            printf("%c",ch);
      }
      return 0;
}

Output:

C_nraeL

.....gnimmargorP C ot emocleW
!gninroM dooG 

hello.txt


 


No comments:

Post a Comment