I wrote the following program to add a '*' character after every vowel in a C string
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char s[99];
cin.get(s, 99);
char aux[99];
for (int i = 0; i < strlen(s); i++)
if(strchr("aeiou", s[i])){
strcpy(aux, s + i);
strcpy(s + i + 1, aux);
s[i+1] = '*';
}
cout << s;
return 0;
}
So if I enter the word brain
it will output bra*i*n
and it works perfectly fine. However if I get rid of that 'aux' string and instead of doing strcpy(aux, s + i); strcpy(s + i + 1, aux);
I just do strcpy(s + i + 1, s + i);
my program stops working. (Infinite looping, doesn't return 0). Why is that?