write a program using pointer to strings that acceptd the name of an animal and a bird and returns the names in plural
#include <iostream>
#include <string.h>
using namespace std;
void change_to_plural(char* input_string, char* output_string) {
int n;
n = strlen(input_string);
if (input_string[n - 1] == 'y') //ends with y
{
input_string[n + 2] = '\0';
input_string[n - 1] = 'i';
input_string[n] = 'e';
input_string[n + 1] = 's';
}
if (input_string[n - 1] == 's' || ((input_string[n - 2] == 's') && (input_string[n - 1] == 'h'))) // ends with s or sh
{
input_string[n] = 'e';
input_string[n + 1] = 's';
input_string[n + 2] = '\0';
}
else //other cases
{
input_string[n] = 's';
input_string[n + 1] = '\0';
}
output_string = input_string;
n = strlen(input_string);
printf("\n================= In plural ==================\n");
for (int i = 0; i < n; i++)
cout << output_string[i];
printf("\n\n");
}
int main() {
char anm[125];
printf("Please input animal name: ");
scanf("%s",anm);
char ot[125];
change_to_plural(anm,ot);
return 0;
}
Comments
Leave a comment