In this tutorial, we will discuss a simple concept of the C program gets() and put() function
Both the functions are used to in the input and output operation of the Strings
The gets() functions are used to read string input from the keyboard and puts() function displays it.
These functions are declared in the stdio.h header file.
The gets() function is similar to scanf() function but it allows entering some characters by the user in string format with the double quotation. and stored in a character array format.
Declaration
Syntax of gets() function
char[] gets(char[]);
Program 1
let’s see an example to read a string using gets() function and print it on the screen using printf() function
#include <stdio.h> #include <stdlib.h> int main() { char ch[30]; printf("Enter the string: "); gets(ch); /reading string using gets() printf("you entered string here\n"); printf(ch);//display out put on the screen using printf() function return 0; }
When the above code is executed, it produces the following results
Enter the string: code4coding you entered string here code4coding
The puts() function is similar to printf() function. but puts() function is used to display only the string after reading by gets() function entered by user(gets similar to scanf() function)
Declaration
Syntax of puts() function
int puts(char[])
Program 2
let’s see an example to read a string using gets() function and print it on the screen using puts() function
#include <stdio.h> #include <string.h> int main() { char sentence[50]; printf("Enter your sentence\n"); gets(sentence);//read input from entered by the user printf("your sentance here\n\n"); puts(sentence); //display the sentence getch(); return 0; }
When the above code is executed, it produces the following results
Enter your sentence Code4coding is a programming portal your sentence here Code4coding is a programming portal
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…