Advertisement
Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <bitset>
  4. #include <string>
  5. #include <stdio.h>
  6. #include "assign2_part1.h"
  7. using namespace std;
  8. void assign2_part1(string arg1){
  9. string filename="";
  10. ifstream fileopen(arg1);
  11. string a;
  12. string b;
  13. int c;
  14. //adding hack behind
  15. arg1 = arg1.substr(0,arg1.length()-4)+".hack";
  16. filename = arg1;
  17.  
  18. //creating a file called input.hack
  19. ofstream outfile (filename);
  20. int counter=1;
  21. while(fileopen >> a){
  22. b =a.substr(1,10);
  23. c = atoi(b.c_str());
  24. outfile<<bitset<16>(c)<<endl;
  25. counter++;
  26. }
  27. outfile.close();
  28. }
  29. int main(int argc, char *argv[]){
  30. //var for the input file names
  31. string arg1="";
  32.  
  33. int counter =0;
  34. //checking if the input count is more than 1
  35.  
  36. //getting the name of the file and appending it to arg1 string
  37. for (int i=1;i<argc;i++) arg1.append(std::string(argv[i]));
  38.  
  39.  
  40. assign2_part1(arg1);
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement