Friday, 22 November 2013

REVERSE FILE CONTENT

#include <stdio.h>
#include <stdlib.h>

int main()
{
   char ch, source_file[20], dest_file[20],temp[500];
int count = 0,i;
   FILE *source, *dest;

   printf("Enter name of file to read :  ");
   gets(source_file);

   source = fopen(source_file, "r");

   printf("Enter name of target file where you want to store reversed characters :  ");
   gets(dest_file);

   dest = fopen(dest_file, "w");
int j=0;
   while( ( ch = fgetc(source) ) != EOF )
{
count += 1;
temp[j] = ch;
j++;
}

i=count-1;
while(i>-1)
{
fputc(temp[i], dest);
i--;
}

   printf("File copied successfully.\n");

   fclose(source);
   fclose(dest);

   return 0;
}

No comments:

Post a Comment