Program to demonstrate gets() and puts() functions in C language

 Program to demonstrate gets() and puts() functions in C language



Image_Alt_Here
Program to demonstrate gets() and puts() functions in C language

Today i'm going to tell you about gets() and puts() functions in C language

{tocify} $title={Table of Contents}

First we will include

Header Files


#include<stdio.h>
#include<string.h>

Declare integers
which will be used while running the program to get the character and diaplay the characters.

like: Data_type Variable_name1, Variable_name2, Variable_name 3, ........., Variable_nameN;


For e.g.

main()
{
    char name1[30],name2[30];
    
}

Here

Sign Description
char Character (Data_type)
name1 Variable_name
[30] Character Limit
You can change the Value

Use of Gets() Function
By using gets() fuction we are taking the input from the user.
E.g. :
  • Enter your name
  • Enter your Friends Name


   	printf("\nEnter your name : ");
    gets(name1);
    printf("\nEnter your Friend's name : ");
    gets(name2);
    

Here gets(name1) & gets(name2) statements are used to store the input given by user in printf() Statements. You can change the text of the marked palce in the above algorithm

Use of puts() Function
By using puts() fuction we are giving the output to the user.
E.g. :
  • your name is :
  • your Friends Name is :


   	printf("\n your name is : ");
    puts(name1);
    printf("\nyour Friend's name is : ");
    puts(name2);

Here puts(name1) & puts(name2) statements are used to show the stored output given by user in gets() Statements. You can change the text of the marked palce in the above algorithm

Resultant syntax/Algorithm of the Progam is:
#include<stdio.h>
#include<string.h>
main()
{
    char name1[30],name2[30];
     printf("\nEnter your name : ");
    gets(name1);
    printf("\nEnter your Friend's name : ");
    gets(name2);
    
    printf("\n your name is : ");
    puts(name1);
    printf("\nyour Friend's name is : ");
    puts(name2);
    
}

You can change the text of the marked palce in the above algorithm

       
Vishvesh Shivam

Vishvesh Shivam is the dynamic founder of TheVsHub.in, a platform he is continually refining with his passion and dedication. A web developer and student based in the scenic Himachal Pradesh, Vishvesh embodies self-reliance and innovation. His quick decision-making ability and relentless drive set him apart, fueling his mission to elevate TheVsHub.in every single day.

Post a Comment

We Love Hearing from You!
Thank you for reading our post! Your thoughts and opinions are important to us. Please leave a comment below to share your feedback, ask questions, or start a discussion. We look forward to engaging with you!

Note: Comments are moderated to ensure a respectful and positive environment.

Previous Post Next Post
Code Copied!