gets() function

The gets() and puts() are declared in the header file stdio.h and both the function are involved in input output operations of the strings.gets() function enables user to enter some character followed by enter key. Null character is added to the array to make it string.It returns the string entered by user.

Declaration of gets() function

char[]gets(char[]);

Let’s see the example of gets() function

#include<stdio.h>  
void main ()  
{  
    char s[30];  
    printf("Enter the string? ");  
    gets(s);  
    printf("You entered %s",s);  
}

Output

Enter the string?

thetechnicalfunda

You entered thetechnicalfunda

puts() function

The puts() function is similar to printf() function and the puts() function is usde to print on the console which is already ready by using gets() or scanf() function.The integer value returned by put() will always be equal to the number of character present in the string plus 1.

Declaration of put() function

int puts(char[])

Let’s see the example of puts() function in language

#include<stdio.h>  
#include <string.h>    
int main(){    
char name[50];    
printf("Enter your name: ");    
gets(name);     
printf("Your name is: ");    
puts(name);    
return 0;    
}

Output

Enter your name : Mishti joshi

Your name is : Mishti joshi

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews