Home » Blog » Use Of gets() Function

Use Of gets() Function

Some of the important point to note ::

  • scanf() and gets() both are used to take input from the user.
  • scanf() can only take input until it encounters a space. The words after space are ignored by it. It means it takes input of only one word.
  • gets() is used to take a single input at a time but can be used to input a complete sentence with spaces unlike scanf(). It means it gets input from user until user hit enter key. gets() takes only a single line at a time.

Example is below

#include<stdio.h>
#include<conio.h>

void main()
{
    char str[50];   // char array or string of size 50
	
    clrscr();
	
    printf("Enter your full name:\n\n");
    gets(str);
	
    printf("\n\nWelcome to TejSumeru  %s\n\n\n", str);
 
    getch();
}

OutPut

Enter your full name:

Suvidha Malaviya
	

Welcome to TejSumeru Suvidha Malaviya

It’s Done. Keep It Up Guys…

Leave a Reply

Your email address will not be published.