Advertisement
khaiwen1111

Tutorial 9 Part B Question 4

Apr 6th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int count_upper(char str[]);
  6. int search_char(char str[], char search_ch);
  7.  
  8. int main(void)
  9. {
  10.     return 0;
  11. }
  12.  
  13. int count_upper(char str[])
  14. {
  15.     int count = 0;
  16.  
  17.     for(int i = 0; i < strlen(str); i++)
  18.         if (isupper(str[i]))
  19.             count++;
  20.     return count;
  21. }
  22.  
  23. int search_char(char str[], char search_ch)
  24. {
  25.     int count = 0;
  26.  
  27.     for(int i = 0; i < strlen(str); i++)
  28.         //if ignore cases -> if(toupper(str[i]) == toupper(search_ch)
  29.         if (str[i] == search_ch)                //case sensitive
  30.             count++;
  31.     return count;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement