annie_02

zad2

Sep 1st, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool space(char ch) {
  5.     if (ch == ' ' || ch == '\t' || ch == '\0')
  6.         return true;
  7.     return false;
  8. }
  9.  
  10. int strlen(char* str) {
  11.     int counter = 0;
  12.     while (str[counter] != '\0') {
  13.         ++counter;
  14.     }
  15.     return counter;
  16. }
  17.  
  18. int evenWords(char* str) {
  19.     int result = 0;
  20.     int len = strlen(str);
  21.     int counter = 0;
  22.     for (int i = 0; i < len; i++) {
  23.         if (!space(str[i])){
  24.             ++counter;
  25.         }
  26.         else {
  27.             if (counter % 2 == 0) {
  28.                 ++result;
  29.             }
  30.             counter = 0;
  31.         }
  32.     }
  33.     return result;
  34. }
  35.  
  36. int main() {
  37.     char arr[] = "this is arr";
  38.     evenWords(arr);
  39. }
Add Comment
Please, Sign In to add comment