I am having a problem with my program. Whenever I input a 10 letter word like montgomery its' output is montgomer@ies. The program is about converting the noun that ends with "y" to "ies".
Code:
include <stdio.h>
#include <string.h>
#define STRING_LEN 20
void check_noun(char *dest, const char *source);
int
main(void)
{
char original[STRING_LEN], changed[STRING_LEN];
printf(" Please enter the noun here> ");
scanf("%s", original);
check_noun(changed, original);
printf(" The plural version of noun is: %s\n ", changed);
return(0);
}
void check_noun(char *dest, const char *source)
{
int num, number;
for(num=0; num < strlen(source); num=num+1)
{
if(source[num]=='y')
{
strncpy(dest, source, num);
strcat(dest, "ies");
}
}
}
Here is what happens when I run the program:
Please enter the noun here> montromery
The plural version of noun is: montromer@ies