Advertisement
Guest User

//3

a guest
Jan 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <string.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.   const int n = 81;
  11.   char word[n];
  12.   //char str2[n];
  13.   cin >> word;
  14.  
  15.   /*ifstream fin ("text.txt", ios::in | ios::nocreate);*/
  16.   ifstream fin("/home/alex/CProject/3/text.txt");
  17.   if ( ! fin.is_open() ) {
  18.     // open failed - probably because infput file does not exist  
  19.   }
  20.   /*if (!fin){
  21.     cout << "Error, file dosn't exist." << endl;
  22.     return 1;
  23.   }*/
  24.  
  25.   char line[n];
  26.  
  27.   int i = 0;
  28.   char *buf = strstr(line, word);
  29.  
  30.   while (fin.getline(line, n)){
  31.     char *buf = strstr(line, word);
  32.     //buf = strstr(line, word);
  33.     while (buf){
  34.         i++;
  35.         buf = strstr(buf+1, word);
  36.     }
  37.   }
  38.  
  39.   cout << i << endl;
  40.  
  41.   fin.close();
  42.   return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement