Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "auxiliar.h"
  4.  
  5. int main(int argc, char *argv[]){
  6. if(argc==1){
  7. Error(EX_NOINPUT, "No hay fichero a leer");
  8. return EX_NOINPUT;
  9. }
  10. if (strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--help")==0)
  11. {
  12. printf ("bocabajo: Uso: bocabajo [ fichero... ]\n");
  13. printf("bocabajo: Invierte el orden de las l´ıneas de los ficheros (o de la entrada).\n");
  14. return EX_OK;
  15. }
  16.  
  17. FILE *file;
  18. char line[2048];
  19. int i,j;
  20.  
  21. for (j=argc-1; j > 0; j--){
  22. int ch;
  23. int count;
  24.  
  25. file = fopen(arv[j], "r");
  26. if (file==NULL){
  27. Error(EX_NOINPUT, "El fichero \"%s\" no puede ser leido ", argv[j]);
  28. return EX_NOINPUT;
  29. }
  30. fseek(fd, 0, SEEK_END);
  31. while (ftell(file) > 1 ){
  32. fseek(file, -2, SEEK_CUR);
  33. if(ftell(file) < 2)
  34. break;
  35. ch =fgetc(file);
  36. count = 0;
  37. while(ch != '\n'){
  38. line[count++] = ch;
  39. if(ftell(file) < 2)
  40. break;
  41. fseek(file, -2, SEEK_CUR);
  42. ch =fgetc(file);
  43. }
  44. for (i =count -1 ; i >= 0 && count > 0 ; i--)
  45. printf("%c", line[i]);
  46. printf("\n");
  47. }
  48. fclose(file);
  49.  
  50.  
  51. }
  52. return EX_OK;
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement