Ticker

6/recent/ticker-posts

C Language (gets and puts function in c)

GETS AND PUTS FUNCTION IN C





GETS FUNCTION
The gets() function is used to read only the string values in C programming language.

SYNTAX OF GETS() FUNCTION
gets(string variable name);

DIFFERENCE BETWEEN SCANF() AND GETS()
The scanf() function is used to read different datatypes inputs (character, integer, float, string) but it cannot read the blank spaces. 
The gets() function is used to read only the string values and it can also read the blank space between the string values. 

GETS() FUNCTION EXAMPLE
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char name[40];
printf("Enter your name: ");
gets(name);
getch();
}

----------------------------
         OUTPUT 
----------------------------

Enter your name:
Rakesh kumar






PUTS FUNCTION
The puts() function is used to display/print only the string values in C programming language.

SYNTAX OF GETS() FUNCTION
puts(string variable name);

DIFFERENCE BETWEEN PRINTF() AND PUTS()
The printf() function is used to display/print the different datatype variable's values (character, integer, float, string)
The puts() function is used to display/print only the string values.

We cannot combine the text message + string variable's value in the puts() function, to combine the text message + variable's value we need to use the printf() function.  

PUTS() FUNCTION EXAMPLE
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char name[40];
printf("Enter your name: ");
gets(name);
puts(name);
getch();
}

----------------------------
         OUTPUT 
----------------------------

Enter your name:
Rakesh kumar
Rakesh kumar







STRLEN IN C >>







HOME

Post a Comment

0 Comments