Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Solution to homework assignment S
- * Introduction to programming course
- * Faculty of Mathematics and Informatics of Sofia University
- * Winter semester 2020/2021
- *
- * @author Anelia Keranova
- * @idnumber 7MI0600055
- * @task 4
- * @compiler VC
- *
- */
- #include <iostream>
- using namespace std;
- bool space(char ch) {
- if (ch == ' ' || ch == '\t' || ch == '\0')
- return true;
- return false;
- }
- int strlen(char* S) {
- int counter = 0;
- while (S[counter] != '\0') {
- ++counter;
- }
- return counter;
- }
- int sumASCII(char* S, char C) {
- int result = 0;
- int len = strlen(S);
- for (int i = 0; i < len; i++) {
- if ((i == 0 && S[i] == C) || (space(S[i-1]) && S[i] == C)){
- while (!space(S[i]))
- result += (int)S[i];
- }
- }
- return result;
- }
- int main() {
- char arr[] = "this is arr";
- cout << sumASCII(arr, 'i');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement