Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define COL_WIDTH 80
- #define MAX_PATH 200
- int main() {
- char x[256];
- int c; // counter for words
- int i; // loop counter
- char filename[MAX_PATH + 1];
- char input_line[COL_WIDTH + 1];
- cout << "Enter a file name and press ENTER: ";
- cin.getline(filename, MAX_PATH);
- ifstream file_in(filename);
- if (! file_in) {
- cout << filename << " could not be opened.";
- cout << endl;
- return -1;
- }
- cout << "Enter a word you are looking for: ";
- cin >> x;
- cout << "You entered the word: " << x << endl;
- while (true) {
- for (i = 1; i <= 24 && ! file_in.eof(); i++) {
- file_in.getline(input_line, COL_WIDTH);
- cout << input_line << "\t line \t" << i << endl;
- }
- } //<--------------------------------------THIS ONE TOO
- while(!file_in.eof())
- { //<----------------------------------------------------------------------------------------------------
- c++;
- string temp; //<-- what is this?
- file_in >> temp;
- if(temp == x)
- { //<---this one
- cout << endl << endl;
- cout << "The word " << x << " was found on line " << c << "\n";
- break;
- } //<--- and this one
- else {cout<<"line " << c << " fail \n";}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement