Advertisement
Miquel_Fuster

Invertir un archivo de texto

Feb 14th, 2022
1,462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     const char *file_in = "test.txt";
  5.     const char *file_out = "output.txt";
  6.  
  7.     FILE *fp_in = fopen(file_in, "r");
  8.     FILE *fp_out = fopen(file_out, "w");
  9.  
  10.     fseek(fp_in, -1, SEEK_END);
  11.     while(ftell(fp_in)) {
  12.         fputc(fgetc(fp_in), fp_out);
  13.         fseek(fp_in, -2, SEEK_CUR);
  14.     }
  15.     fputc(fgetc(fp_in), fp_out);
  16.  
  17.     fclose(fp_out);
  18.     fclose(fp_in);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement