ShEeRMiLiTaNt 0 Newbie Poster

Hello,
I need help with something. I need to write a program that goes into a text file and searches the characters one by one until it finds a group of them that I need, to store into another character array. The group of characters is "7 people who...will fail! LOL!" Here is what I have so far.

#include <iostream>
#include <fstream>

using namespace std;

//void input(string& );
//Precondition: User is ready to enter values correctly.
//Postcondition: Return the name in correct format (first letter captilaized
//everything else lower case.)

void file_search(char [30], char [30], ifstream& input);
//Precondition: Input name has to be in correct format.
//Postcondition: Searches the file and prints the rank of the imput name on
//the screen.

char name[30], search[30]={'7 People who...will fail! LOL!'};


int main()
{
    cout << "Hello!\n";

    ifstream in;


    //input(name);
    file_search(name, search, in);

    cout << "Goodbye!\n";

    return 0;
}


/*void input(string& inputName)
{
    cout << "Hello!\n" << endl
         << "Please enter the name you wish to search for: ";
    cin >> inputName;

    int l= inputName.length();
    inputName[0] = toupper(inputName[0]);
    for(int i = 1; i < l; i++)
    {
        if(inputName[i]!=' ')
        {
            inputName[i] = tolower(inputName[i]);
        }
    }
}*/

void file_search(char name[30], char search[30], ifstream& input)
{
    input.open("Text.txt");
    if (input.fail())
    {
        cout << "Error opening Text.txt.\n";
    }
    while(input.good())
    {
        while (input >> name)
        {
            input >> name;
            if (name == search)
            {
                cout << "I found it!\n";
            }
    }
    input.close();
    cout << "\n";
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.