Advertisement
wikypoo

Untitled

Feb 8th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4.  
  5. using namespace std;
  6.  
  7. fstream CreatAsciiArt (string filename){
  8. // file that program will create
  9. fstream newfile;
  10. // object for fstream class
  11. fstream file;
  12.  
  13. // opening file
  14. file.open(filename.c_str(), ios::in);
  15.  
  16. // checking if file has opened
  17. while (file.bad()) {
  18. cout << "There was an error opening the file " << endl;
  19. cout << "File name:";
  20. cin >> filename;
  21. file.open(filename.c_str(), ios::in);
  22. }
  23. int spacecount = 0;
  24. int charcount = 0;
  25. int linecount = 1;
  26. int linelength;
  27. string line;
  28.  
  29. while (file.good()) {
  30. //gets new line
  31. getline(file, line);
  32. //get length of the new line
  33. linelength = line.length();
  34.  
  35. for(int i = 0; i < linelength; i++) {
  36. //ignores first character which is line number
  37. if (i == 0) {
  38.  
  39.  
  40. }
  41. // ignores second character
  42. if (i == 1) {
  43.  
  44.  
  45. }
  46. // excludes all spaces and commas
  47. if ((line.at(i) != ' ') && (line.at(i) != '-') && (line.at(i) != ',') && (i != 0)) {
  48.  
  49. // checks number of spaces for "sp" that are 2 digits
  50. if (line.at(i) == 's' && line.at(i + 1) == 'p') {
  51. if (isdigit(line.at(i - 3))) {
  52.  
  53. cout << line.at(i - 3) << line.at(i - 2) << endl;
  54.  
  55.  
  56.  
  57. }
  58.  
  59. // checks number of spaces for "sp" that are 1 digits
  60. else {
  61. cout << (line.at(i - 2)) << endl;
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement