Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
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.

util.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef __UTIL_H__
  2. #define __UTIL_H__
  3. #include <vector>
  4. #include <iostream>
  5. #include <fstream>
  6. vector<string> open_file(string file_name) {
  7. ifstream myfile;
  8. vector<string> data;
  9. myfile.open(file_name.c_str());
  10. string temp;
  11. while(!myfile.eof()) {
  12. getline(myfile, temp);
  13. data.push_back(temp);
  14. }
  15. myfile.close();
  16. return data;
  17. }
  18. bool get_file_name(string input) {
  19. bool file_correct = false;
  20. string input_file_name;
  21. while(!file_correct) {
  22. ifstream inputs(input.c_str());
  23. if(inputs.good()) {
  24. input_file_name = input;
  25. file_correct = true;
  26. open_file(input_file_name);
  27. return true;
  28. }
  29. else {
  30. cerr << "incorrect file name" << endl;
  31. return false;
  32. }
  33. }
  34. return false;
  35. }
  36. void write_file(string output, string file_name) {
  37. ofstream myfile;
  38. myfile.open(file_name.c_str());
  39. myfile << output << "\n";
  40. }
  41. void write_file(vector<string> output, string file_name) {
  42. ofstream myfile;
  43. myfile.open(file_name.c_str());
  44. for(unsigned int i = 0; i < output.size(); i++) {
  45. if(i != output.size() -1) {
  46. myfile << output[i] << "\n";
  47. }
  48. myfile << output[i];
  49. }
  50. }
  51. #endif