Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int bialy(char znak);
- int wyrazy(string text);
- int main(int argc, char** argv)
- {
- fstream plik;
- plik.open("text.txt", ios::in);
- if ( plik.good() == true )
- {
- string text;
- getline(plik, text);
- cout <<text;
- cout << text.size() << " " << wyrazy(text);
- }
- else if ( plik.good() == false )
- {
- cout << "no przepraszam";
- }
- return 0;
- }
- int bialy(char znak)
- {
- return (znak == ' ' || znak == '\n' || znak == '\t' || znak == '\r');
- }
- int wyrazy(string text)
- {
- char ost=' ';
- int slowa=0;
- for(size_t i=0; i < text.size(); ++i)
- {
- char ch = text.c_str()[i ];
- if (bialy(ch) && !bialy(ost))
- {
- slowa=slowa+1;
- }
- char ost = text[i ];
- }
- return slowa;
- }
Advertisement
Add Comment
Please, Sign In to add comment