hello
im writing a function to change nouns to plurals
every condition is working great except words ending with y
it should work like input : fly output :flies
but the output comes out as : flis
this is my function code for this part
int n;
n=strlen(input_string);
if (input_string [n-1]=='y')
{
input_string[n+2]='\0';
input_string[n-1]='i';
input_string[n]='e';
input_string[n+1]='s';
}
//for outputting
output_string = input_string;
n = strlen(input_string);
for(int i = 0; i < n; i++)
cout << output_string[i];
You are overwriting the bounds of the string, so of course you are getting undefined behavior. Instead, only overwrite the y and append the other two characters with the += operator.