unsure how to go about this

I am playing around manipulating strings and currently I want to take a full name typed in by a user eg. "Mike W. Heintzman" and then take three letters input by the user, eg. M I E and then I want it to find all of those instances in the name. I have upto this point complete. What I cannot figure out how to do is this next part. I want to take the information from above and delete those characters print out the name without the given letters and then reinsert those letters into their previous position this is the code I have so far. Im not looking for an answer I just need help getting in the ready right direction.

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
//define the lettersearch function
string letterSearch(string fullName) {
    //create an array to hold the users entered variables
    char userLetters[3];
    //create a var to hold the letter positions
    int found;
    //Create a multi dimensional array to hold the letters removed and their posion the first
    int letterPos[3][2];
    //make full name all lowercase since C++ is a case senseative language
    fullName = strLowerCase(fullName);
    //tell the user to enter letters
    cout << "\n Please enter three letters that are in your name.\n This search is case insensitive. " << endl;
    //create a for loop to fill the array with answers
    for (int i = 0; i < 3; i++){
        //set the array with i
        cin >> userLetters[i];
    }
    system("CLS");
    //create a for loop to check for individual letters in the string fullname
    for (int i = 0; i < 3; i++){
        //set the search make make sure everything is lowercase
      found = fullName.find(tolower(userLetters[i]));
      //continue in this while loop untill there are not more instances of a given letter
        while (found != string::npos){
            //display what letter has been found and in what position
             cout << "\n The letter " << userLetters[i] << " has been found at " << found << endl;
             letterPos[i][0] = found;
             char test = atoi(userLetters[i]);
             letterPos[i][1] = test;
             //continue the search from the last position
              found=fullName.find(tolower(userLetters[i]),found+1);
        }
    }
    return "test";
    }
bump
Is this an exercise? If so, do you have the original problem statement? If not, do have any restrictions?

For example, are you expected to remove and then add the chars from/to the existing string, fullName?

Andy

PS

char test = atoi(userLetters[i]);

Doesn't look right. atoi() takes a const char*, not a char
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/

why not just

char test = userLetters[i];

afterall, userLetters is an array of chars?
Last edited on
Topic archived. No new replies allowed.