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

       

Comments

Popular posts from this blog

Implementing Auto-Logout in PHP: Enhancing Security for Your Web App

A Simple and Professional Login Form with Gradient Background

How to Create a YouTube Subscribe Website Widget