Inserting something in a string after certain pre-defined characters

Hi. I'm working on an assignment which asks me to translate a sentence given by the user into "chicken language"(I think this is only valid in the language spoken in my country, which is Romanian). Basically what this means is after every vowel(a e i o u) I must insert the letter 'p' followed by the respective vowel. Example: "How you doin'?" translates into "Hopow yopoupu dopoipin'?". I must achieve this by USING POINTERS. What I am having trouble with is actually changing the value of what the pointer points to into what I need. If the pointer meets an 'e' I must change the 'e' to 'epe', so *p becomes *p+p+*p. How can I express this? Check line 10.

1
2
3
4
5
6
7
8
9
10
11
12
13
  int main()
{	
	char s[30];
	cout<<"Enter sentence: ";
	cin.getline(s,30);
	char *p = s;
	for(int i=0; i<strlen(s);i++){
		if(*p=='A'||*p=='a'||*p=='E'||*p=='e'||*p=='I'||
			*p=='i'||*p=='O'||*p=='o'||*p=='U'||*p=='u'){
			*p=*p+'p'+*p;
	}
	return 0;
}
Last edited on
The problem is that you're overwriting the next letters to be processed.

One way to deal with this is to write the output into a new string, rather than working in the same string.
Wow, that was easy! Took me 10 minutes to do it after reading your answer. Thanks you!
Topic archived. No new replies allowed.