cs1713-test1-bonus.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2020, 2019, 2018, 2017 Girish M
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. * MA 02110-1301, USA.
  17. *
  18. */
  19. /*
  20. Problem statement: https://www.isical.ac.in/~pdslab/2017/exams/labtest1.pdf
  21. */
  22. #include "common.h"
  23. int main(int argc, char* argv[])
  24. {
  25. if(argc == 3)
  26. {
  27. FILE* fptr;
  28. int c, num_bytes = 0;
  29. if((fptr = fopen(argv[2], "r")))
  30. {
  31. while((c = fgetc(fptr)) != -1)
  32. {
  33. num_bytes++;
  34. if((num_bytes % atoi(argv[1])) == 0)
  35. {
  36. printf("\n");
  37. }
  38. else
  39. printf("%.2X ", c);
  40. }
  41. printf("\n");
  42. fclose(fptr);
  43. }
  44. else
  45. printf("\nCould not open %s\n", argv[2]);
  46. }
  47. else
  48. printf("\nUsage: ./cs1713-test1-bonus.o num_bytes fileName\n");
  49. return 0;
  50. }