Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <bitset>
- #include <string>
- #include <stdio.h>
- #include "assign2_part1.h"
- using namespace std;
- void assign2_part1(string arg1){
- string filename="";
- ifstream fileopen(arg1);
- string a;
- string b;
- int c;
- //adding hack behind
- arg1 = arg1.substr(0,arg1.length()-4)+".hack";
- filename = arg1;
- //creating a file called input.hack
- ofstream outfile (filename);
- int counter=1;
- while(fileopen >> a){
- b =a.substr(1,10);
- c = atoi(b.c_str());
- outfile<<bitset<16>(c)<<endl;
- counter++;
- }
- outfile.close();
- }
- int main(int argc, char *argv[]){
- //var for the input file names
- string arg1="";
- int counter =0;
- //checking if the input count is more than 1
- //getting the name of the file and appending it to arg1 string
- for (int i=1;i<argc;i++) arg1.append(std::string(argv[i]));
- assign2_part1(arg1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement