Originally Posted by
laurenlb
I'm learning strings and I have to write a program that (along with other things) takes a singular form of a noun and makes it plural. More specifically, the one I'm working with now is if the noun is baby, it would drop the "y" and add an "ies".
The only part I have left to figure out is how to drop the "y" off the end of baby before using strcat to put "bab" and "ies" together to make it "babies".
Any ideas/tips?
You don't need to remove the y first... just overwrite it with the new data.
Code:
char text[100];
char *ptr;
strcpy(text,"Baby");
// find the y
ptr = strchar('y');
// change to plural
if (ptr)
strcpy(ptr,"ies");
printf("%s", text);