Advertisement
annie_02

zAD3

Sep 1st, 2022
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 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 2020/2021
  7. *
  8. * @author Anelia Keranova
  9. * @idnumber 7MI0600055
  10. * @task 4
  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* S) {
  25. int counter = 0;
  26. while (S[counter] != '\0') {
  27. ++counter;
  28. }
  29. return counter;
  30. }
  31.  
  32. int sumASCII(char* S, char C) {
  33. int result = 0;
  34. int len = strlen(S);
  35. for (int i = 0; i < len; i++) {
  36. if ((i == 0 && S[i] == C) || (space(S[i-1]) && S[i] == C)){
  37. while (!space(S[i]))
  38. result += (int)S[i];
  39. }
  40. }
  41. return result;
  42. }
  43.  
  44. int main() {
  45. char arr[] = "this is arr";
  46. cout << sumASCII(arr, 'i');
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement