Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. int main(int argc, char *argv[])
  2. {
  3. FILE *fp_in;
  4. FILE *fp_out;
  5.  
  6. // Zad.2
  7. if (argc != 4)
  8. {
  9. printf("nieprawidlowa liczba parametrow\n");
  10. exit(1);
  11. }
  12.  
  13. char *input_file = argv[1];
  14. char *output_file = argv[2];
  15. char *mode = argv[3];
  16.  
  17. // Zad.3
  18. if ((fp_in = fopen(input_file, "rb")) == NULL)
  19. {
  20. printf("Nie udalo sie otworzyc pliku wjesciowego\n");
  21. exit(1);
  22. };
  23.  
  24. if ((fp_out = fopen(output_file, "wb")) == NULL)
  25. {
  26. printf("Nie udalo sie otworzyc pliku wyjsciowego\n");
  27. exit(1);
  28. };
  29.  
  30. // Zad.4
  31. fseek(fp_in, 0, SEEK_END);
  32. int size_in = ftell(fp_in);
  33. fseek(fp_in, 0, 0);
  34. char *buffor = malloc((size_in)+1);
  35. fread(buffor, 1, size_in, fp_in);
  36. buffor[(size_in)] = 0;
  37.  
  38.  
  39. if (strcmp(mode, "-copy")==0)
  40. {
  41. copy(buffor, fp_out, size_in);
  42. }
  43. else
  44. {
  45. if (strcmp(mode,"-replace") == 0)
  46. {
  47. replace(buffor, fp_out, size_in);
  48. }
  49. }
  50.  
  51. fclose(fp_in);
  52. fclose(fp_out);
  53. free(buffor);
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement