//Ask user what string they would like to find. void userFind(stringstream& ss) { extern char** environ; char* choice = new char [WORD_SIZE]; char* word = new char [WORD_SIZE]; char* environment = new char [WORD_SIZE]; char temp; int numLine = 0; int count = 0; int lines = 0; streampos gpos, ppos; ss.str(ss.str()); ss.seekp(0, ss.beg); ss.seekg(0, ss.beg); ss.clear(); //Ask user what string they would like to search for. cout << "Please enter a string to search or \"END\" to quit. \n"; cin >> choice; transform(choice, (choice + strlen(choice)), choice, ::toupper); while(strcmp(choice, "END") != 0) { //Search the stringstream for each occurance of the string. while(ss.getline(word, WORD_SIZE, ' ')) { transform(word, (word + strlen(word)), word, ::toupper); if(strcmp(word, choice) == 0) { //cout << "Word found!" << endl; count++; while(environ[lines]) { transform(environ[lines], (environ[lines] + strlen(environ[lines])), environment, ::toupper); if(strstr(environment, word)) cout << environ[lines] << endl; lines++; } //Incrememnt numLine for each newline character we find. //And print out the corresponding line. } } //Then print out how many times the string appeared. cout << "Found " << count << " results!\n"; cout << endl; cout << "Please enter a string to search or \"END\" to quit. \n"; cin >> choice; transform(choice, (choice + strlen(choice)), choice, ::toupper); ss.str(ss.str()); ss.seekp(0, ss.beg); ss.seekg(0, ss.beg); ss.clear(); count = 0; } //delete environment; delete choice; delete word; return; }