Jabberwocky submission for Computer Organization
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
630 B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. void atob ( FILE *ifp, FILE *ofp );
  5. int main( int argc, char *argv[] ) {
  6. FILE *ifp, *ofp;
  7. if (argc < 3) {
  8. fprintf(stderr, "Not enough arguments\n");
  9. exit(1);
  10. }
  11. if (!(ifp = fopen(argv[1],"r"))) {
  12. fprintf(stderr,"Cannot open file %s\n",argv[1]);
  13. exit(1);
  14. }
  15. if (!(ofp = fopen(argv[2],"w"))) {
  16. fprintf(stderr,"Cannot open file %s\n",argv[2]);
  17. exit(1);
  18. }
  19. atob(ifp, ofp);
  20. return 0;
  21. }
  22. void atob ( FILE *ifp, FILE *ofp ) {
  23. char c;
  24. while ((c = fgetc(ifp)) != EOF) {
  25. char i;
  26. for (i = 7; i >= 0; --i) {
  27. fputc('0' + (c >> i & 1), ofp);
  28. }
  29. }
  30. }