I am trying to set up a function that looks at a string of text, and replaces "y" with "ies" to make it plural.
The problem I am having here (aside from ignorance), is that the function will not enter the 1st nested if statement. (
char noun_to_plural(char n[10])
{
int length;
char temp[10];
char replace[10];
length = strlen(n); //This returns 3 correctly when passed "fly"
printf("length is %d\n", length );
if (length == 3 ) //Successfully enters this statement
{
printf("1st Loop Entered\n");
strcpy(temp, &n[length -1]); //correctly retuns "y" for value temp.
printf("Temp value is %s\n", temp);
if (temp == 'y') //It will not pass into this if condition even
//though temp is 'y'
{
printf("2nd Loop Entered");
replace[10] = strcpy(replace, n );
replace[3] = 'i';
replace[4] = 'e';
replace[5] = 's';
printf("Loop entered test-%s-test", n ); //returns string "fly"
}
}
}
Lastly, is there an easier way to change the 'y' into 'ies' that I am missing? This function isn't complete obviously as I am struggling to get it to go into the 2nd condition. I even tried using:
if (strcpy(temp, &n[length -1] == 'y')
and that didn't work either.