Advertisement
Guest User

Untitled

a guest
May 28th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. #define COL_WIDTH 80
  5. #define MAX_PATH 200
  6.  
  7. int main() {
  8.         char x[256];
  9.         int c; // counter for words
  10.         int i; // loop counter
  11.         char filename[MAX_PATH + 1];
  12.         char input_line[COL_WIDTH + 1];
  13.  
  14.         cout << "Enter a file name and press ENTER: ";
  15.         cin.getline(filename, MAX_PATH);
  16.         ifstream file_in(filename);
  17.  
  18.         if (! file_in) {
  19.                 cout << filename << " could not be opened.";
  20.                 cout << endl;
  21.                 return -1;
  22.         }
  23.        
  24.         cout << "Enter a word you are looking for: ";
  25.         cin >> x;
  26.         cout << "You entered the word: " << x << endl;
  27.        
  28.         while (true) {
  29.                 for (i = 1; i <= 24 && ! file_in.eof(); i++) {
  30.                         file_in.getline(input_line, COL_WIDTH);
  31.                         cout << input_line << "\t line \t" << i << endl;
  32.                 }
  33.         } //<--------------------------------------THIS ONE TOO
  34.  
  35.     cout<<"test\n";
  36.  
  37.         while(!file_in.eof())
  38.         { //<----------------------------------------------------------------------------------------------------
  39.                         c++;
  40.                         string temp; //<-- what is this?
  41.                         file_in >> temp;
  42.                 if(temp == x)
  43.                 { //<---this one
  44.                         cout << endl << endl;
  45.                         cout << "The word " << x << " was found on line " << c << "\n";
  46.                         break;
  47.                 } //<--- and this one
  48.                 else {cout<<"line " << c << " fail \n";}
  49.         }
  50.  
  51.         return 0;
  52.  
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement