Advertisement
Guest User

Untitled

a guest
Feb 12th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h";
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     char tekst[100];
  8.  
  9.     cout << "Podaj tekst do policzenia znakow i wyrazow: ";
  10.     cin.get(tekst, 100); // limit 100 znakow
  11.  
  12.     int znaki = 0;
  13.     int wyrazy = 0;
  14.  
  15.     int czySpacja = true;
  16.  
  17.     for (int i = 0; i < strlen(tekst); ++i) {
  18.         if (isspace(tekst[i])) {
  19.             czySpacja = true;
  20.         }
  21.         else
  22.         {
  23.             if (czySpacja) {
  24.                 wyrazy++;
  25.             }
  26.             czySpacja = false;
  27.             znaki++;
  28.         }
  29.     }
  30.  
  31.     cout << "Statystyki podanego tekstu: znaki: " << znaki << ", wyrazy: " << wyrazy << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement