Answer to Question #233223 in C for M.Surya Saketh

Question #233223
Write a program using pointer to strings that accepts the name of an animal and a bird and returns the names in plural.
1
Expert's answer
2021-09-04T10:55:27-0400
#include <stdio.h>
#include <string.h>




int main()
{
	char *nameAnimal = (char*) malloc(50*sizeof(char));
	char *nameBird = (char*) malloc(50*sizeof(char));
	int n;	


	printf("Enter name of animal: ");
	gets(nameAnimal);
	printf("Enter name of animal: ");
	gets(nameBird);


	strncat(nameAnimal,"s", 1);
	strncat(nameBird,"s", 1);


	printf("\nNames in plural are: %s, %s\n",nameAnimal,nameBird);




	free(nameAnimal);
	free(nameBird);




	scanf("%d",&n);


	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
New on Blog
APPROVED BY CLIENTS