Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <windows.h>
  6. using namespace std;
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10. int spacesToRemove = -1;
  11.  
  12. if (argc == 1 || argc > 3)
  13. {
  14. cout << "Please provide a directory to the file, in which you want to remove unwanted spaces.\n"
  15. << "You can do this in two ways:\n"
  16. << "1. Drag .txt file onto the executable of this program;\n"
  17. << "2. Open cmd and provide a directory to this program's executable,\n"
  18. << "then after space a directory to your .txt file, optionally you can provide\n"
  19. << "a number of spces to remove, i.e.:\n"
  20. << "C:\\RemoveSpaces.exe C:\\MyTxtFile.txt 5\n";
  21. system("pause");
  22. return 1;
  23. }
  24. else if (argc == 2)
  25. {
  26. cout << "Please provide a number of spaces to remove: ";
  27. cin >> spacesToRemove;
  28. }
  29. else if (argc == 3)
  30. {
  31. spacesToRemove = atoi(argv[2]);
  32. }
  33.  
  34. ifstream file;
  35. ofstream newFile;
  36.  
  37. file.open(argv[1]);
  38. newFile.open(strcat(argv[1], "new"));
  39.  
  40. string str;
  41.  
  42. while (true)
  43. {
  44. getline(file, str);
  45.  
  46. if (str.length() > spacesToRemove)
  47. {
  48. str = str.substr(spacesToRemove);
  49. }
  50.  
  51. newFile << str << '\n';
  52.  
  53. if (file.eof())
  54. {
  55. break;
  56. }
  57. }
  58.  
  59. newFile.close();
  60. file.close();
  61. system("pause");
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement