Write a program to print the accepted character using puts() function.

#include<stdio.h>
#include<conio.h>
int main()
{
	char ch[30];
	printf("Enter the string:-");
	gets(ch);
	puts("Entered string:-");//Display the string puts() fuction is used.//
	puts(ch);
	getch();
}
/*This fuction prints the string or character array.It is opposite to gets().
char str[length of string in no]
gets(str);
puts(str);
*/

The program first declares a character array ch of size 30. The user is prompted to enter a string using printf() statement. The gets() function reads a line of characters from the keyboard and assigns it to the character array ch.

The program then uses the puts() function to display the entered string on the screen. The puts() function is used twice – the first puts() function displays a message “Entered string:” and the second puts() function displays the contents of the character array ch.

Finally, getch() function is used to hold the output screen until a character is entered from the keyboard.

Thanks

Write a program to print the accepted character using puts() function.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top