Advertisement
annie_02

zad3.0

Sep 1st, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /**
  2. *
  3. * Solution to homework assignment S
  4. * Introduction to programming course
  5. * Faculty of Mathematics and Informatics of Sofia University
  6. * Winter semester 2021/2022
  7. *
  8. * @author Anelia Keranova
  9. * @idnumber 7MI0600055
  10. * @task 3
  11. * @compiler VC
  12. *
  13. **/
  14.  
  15. #include <iostream>
  16. using namespace std;
  17.  
  18. bool space(char ch) {
  19. if (ch == ' ' || ch == '\t' || ch == '\0')
  20. return true;
  21. return false;
  22. }
  23.  
  24. int strlen(char* str) {
  25. int counter = 0;
  26. while (str[counter] != '\0') {
  27. ++counter;
  28. }
  29. return counter;
  30. }
  31.  
  32. int evenWords(char* str) {
  33. int result = 0;
  34. int len = strlen(str);
  35. int counter = 0;
  36. for (int i = 0; i < len; i++) {
  37. if (!space(str[i])){
  38. ++counter;
  39. }
  40. else {
  41. if (counter % 2 == 0) {
  42. ++result;
  43. }
  44. counter = 0;
  45. }
  46. }
  47. return result;
  48. }
  49.  
  50. int main() {
  51. char arr[] = "this is a string ";
  52. cout << evenWords(arr);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement