Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5. char* doubleSymbol(char* s, char c)
  6. { char *m;
  7. int count=0, a=0,ccount=0;
  8. a=strlen(s);
  9. cout << a << endl;
  10.  
  11. for (int i=0; i<a;i++)
  12. if (s[i]==c)
  13. count++;
  14.  
  15. cout << count << endl;
  16. cout << a+count << endl;
  17. m=new char[a+count];
  18.  
  19. for (int i=0;i<a+count;++i)
  20. {
  21. if (s[i]!=c)
  22. {
  23. m[i+ccount]=s[i];
  24. }
  25. else
  26. {
  27. m[i+1]=c;
  28. ccount++;
  29. }
  30. }
  31. return m;
  32. }
  33. int main()
  34. {
  35. char str[1000];
  36. char letter;
  37. cout << "Type something here" << endl;
  38. cin.getline(str,1000);
  39. cout << "Type a letter you want to double" << endl;
  40. cin >> letter;
  41. cout << doubleSymbol(str,letter);
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment