Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- char* doubleSymbol(char* s, char c)
- { char *m;
- int count=0, a=0,ccount=0;
- a=strlen(s);
- cout << a << endl;
- for (int i=0; i<a;i++)
- if (s[i]==c)
- count++;
- cout << count << endl;
- cout << a+count << endl;
- m=new char[a+count];
- for (int i=0;i<a+count;++i)
- {
- if (s[i]!=c)
- {
- m[i+ccount]=s[i];
- }
- else
- {
- m[i+1]=c;
- ccount++;
- }
- }
- return m;
- }
- int main()
- {
- char str[1000];
- char letter;
- cout << "Type something here" << endl;
- cin.getline(str,1000);
- cout << "Type a letter you want to double" << endl;
- cin >> letter;
- cout << doubleSymbol(str,letter);
- return 0;
- }
Add Comment
Please, Sign In to add comment