All pastes #475241 Raw Edit

Stuff

public text v1 · immutable
·published 2007-05-07 10:21 UTC
rendered paste body
/**
 * findWaldo
 * 
 * Search for the name "Waldo" in a list of names. If found, save the 
entire 
 * list to an external file called "nameslist.txt".
 *
 * @param nameList - list of names ("Alice", "Bob", etc.)
 * @param searchFrom - index in the list from which to search
 * @return true if "Waldo" is in the list, false otherwise
 */
bool findWaldo(NameList* nameList, int searchFrom)
{
    if(nameList->size() > 1000)
        // list is too big
        return false;

    File* myFile = new File("nameslist.txt");      

    bool found;
    for(int i = 0; i <= nameList->size(); i++)
    {
        if(nameList->getItem(i) == "waldo")
        {
            found = true;

            if(!nameList->writeToFile(myFile))
            {
                ERROR("Could not write to file");
                return found;
            }
        }
    }

    delete myFile;
    return found;
}