Guest User

Untitled

a guest
Jan 28th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. int bialy(char znak);
  6. int wyrazy(string text);
  7. int main(int argc, char** argv)
  8. {
  9.     fstream plik;
  10.     plik.open("text.txt", ios::in);
  11.     if ( plik.good() == true )
  12.     {
  13.         string text;
  14.         getline(plik, text);
  15.         cout <<text;
  16.         cout << text.size() << " " << wyrazy(text);
  17.        
  18.     }
  19.     else if ( plik.good() == false )
  20.     {
  21.         cout << "no przepraszam";
  22.     }
  23.     return 0;
  24. }
  25. int bialy(char znak)
  26. {
  27.     return (znak == ' ' || znak == '\n' || znak == '\t' || znak == '\r');
  28. }
  29. int wyrazy(string text)
  30. {
  31.     char ost=' ';
  32.     int slowa=0;
  33.     for(size_t i=0; i < text.size(); ++i)
  34.     {
  35.         char ch = text.c_str()[i ];
  36.         if (bialy(ch) && !bialy(ost))
  37.         {
  38.             slowa=slowa+1;
  39.         }      
  40.         char ost = text[i ];      
  41.     }
  42.     return slowa;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment