Answer to Question #333259 in C for nova

Question #333259

write a program using pointer to strings that acceptd the name of an animal and a bird and returns the names in plural


1
Expert's answer
2022-04-25T04:43:07-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS