The Question!

Hello All!

This is what I want to accomplish:

1). Open a .txt file containing words in a list.
2). Add to the end of each word the number 1, repeat the process but this time add 12 to end, and 123, and so on...
3). Display the words with the 1/12/123 added to them in the console
4). Write that output to a new file.

So far I have accomplished 1-3 but am stuck on 4.

Here is my code, any help is appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
void centertext(char* s);
int UserChoice();
int main() 
{    
  int a; 
  a = UserChoice();
  if(a==5){
      centertext("Thankyou for using Wordlist Generator 1.1!");
      cout << endl;
      cout << "Press ENTER to continue..." << endl;
  cin.ignore();cin.get();
  exit(1);
  }     
  string nDirectory;
  string buffer;
  cout << "Please enter path to the file: " << endl;
  string fDirectory;
  cin >> fDirectory;
  fstream myfile(fDirectory.c_str());

  while (!myfile.eof())
  {
    myfile >> buffer; 
    buffer[0] = toupper(buffer[0]);
    if(a==1) {
    cout << buffer << "1" << endl;  
    }
    else if(a==2){
    cout << buffer << "12" << endl;    
    }
    else if(a==3){
    cout << buffer << "123" << endl; 
    }
    else if(a==4){
        cout << buffer << "1" << endl;
        cout << buffer << "12" << endl;
        cout << buffer << "123" << endl;      
    }
  }

cout << "Press ENTER to continue..." << endl;
cin.ignore();cin.get();
return 0;
}

int UserChoice() {
    int x;
    cout << "Welcome to the Word List Generator Version 1.0" << endl;
    cout << "Please choose from the following options: " << endl;
    cout << "1. Append 1 to the end of each and every word and Capitalize first char" << endl;
    cout << "2. Append 12 to the end of each and every word and Capitalize first char" << endl;
    cout << "3. Append 123 to the end of each and every word and Capitalize first char." << endl;
    cout << "4. Append 1, then 12, then 123 to each and every word and Capitalise first char." << endl;
    cout << "5. Exit" << endl;
    cin >> x;
    cout << endl;
    cout << "You chose option: " << x << endl;   
    cout << endl;
    return x;
}

void centertext(char* s){
    int l = strlen(s);
    int pos = (int)((80-l)/2);
    for(int i=0; i<pos; i++) 
        cout << " ";
    cout << s << endl;   
}
Topic archived. No new replies allowed.