Advertisement
Cinestra

Double a (Solution without making another string)

Jan 12th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. char double_a(char string[])
  6. {
  7. for (int i = 0; i < strlen(string); i++)
  8. {
  9. if (string[i] == 'a')
  10. {
  11. for (int j = strlen(string); j > i + 1; j--)
  12. {
  13. string[j] = string[j - 1];
  14. }
  15.  
  16. string[i + 1] = 'a';
  17. }
  18. }
  19.  
  20. //Needs to return an actual string, but I'm too lazy to finish it off
  21. }
  22.  
  23. int main()
  24. {
  25. char base[20] = "Yoona eats flowers";
  26.  
  27. double_a(base);
  28. cout << base;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement