Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <string.h>
- #include <fstream>
- using namespace std;
- int main()
- {
- const int n = 81;
- char word[n];
- //char str2[n];
- cin >> word;
- /*ifstream fin ("text.txt", ios::in | ios::nocreate);*/
- ifstream fin("/home/alex/CProject/3/text.txt");
- if ( ! fin.is_open() ) {
- // open failed - probably because infput file does not exist
- }
- /*if (!fin){
- cout << "Error, file dosn't exist." << endl;
- return 1;
- }*/
- char line[n];
- int i = 0;
- char *buf = strstr(line, word);
- while (fin.getline(line, n)){
- char *buf = strstr(line, word);
- //buf = strstr(line, word);
- while (buf){
- i++;
- buf = strstr(buf+1, word);
- }
- }
- cout << i << endl;
- fin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement