Advertisement
Guest User

Journal 7B Application of Pointers

a guest
Apr 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. /*Adeline Delgleize
  2. Student ID 0515277
  3. Journal 7B
  4. Application of Pointers
  5. April 27, 2017*/
  6.  
  7. #include<iostream>
  8.  
  9. using namespace std;
  10.  
  11. int xDigits(char *str, char change);
  12.  
  13. int main()
  14. {
  15.  
  16. char s[] = "Abc12cdextz99052ab";
  17.  
  18. char change;
  19. cout << "Enter character to change: " << endl;
  20. cin >> change;
  21.  
  22.  
  23. int cnt = xDigits(s, change);
  24. cout << "Modified " << cnt << " digits, here is your string. " << endl;
  25. cout << s << endl;
  26.  
  27.  
  28. return 0;
  29. }
  30.  
  31. int xDigits(char *str, char change)
  32. {
  33. char *p = str; //create pointer set it to first character in the string
  34. int count = 0;
  35.  
  36. while (*p)
  37. {
  38. if (*p == change)
  39. {
  40. *p = 'x';
  41. count++;
  42. }
  43.  
  44. p++;
  45.  
  46. }
  47.  
  48. return count;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement