fork(1) download
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. char s[100];
  9.  
  10. cout << "The string is: " << endl;
  11. cin.get(s, 100);
  12.  
  13. int len = strlen(s);
  14. for (int i = 0; i < len; i++) {
  15. if (s[i] == 'a') {
  16. if ((len+3) > sizeof(s)) break; // no more space!
  17. memmove(s+(i+3), s+(i+1), sizeof(s)-(i+1));
  18. s[i+1] = 'a'; s[i+2] = 'a';
  19. i += 2;
  20. len += 2;
  21. }
  22. }
  23.  
  24. cout << "The modified string is: " << endl;
  25. cout << s;
  26. }
Success #stdin #stdout 0s 4956KB
stdin
water
stdout
The string is: 
The modified string  is: 
waaater