gets() Library Functions with Examples
gets()
is string input functions. It reads string from the keyboard. It reads string until enter is pressed. It is defined in header file stdio.h
.
gets() Syntax
gets(string_variable);
gets() Examples
Example #1 : Reading String Using gets() Function
#include<stdio.h>
#include<conio.h>
void main()
{
char name[100];
clrscr(); /* Clear the screen */
printf(“Enter your name:\n”);
gets(name);
printf("Hello %s, Have a nice day.", name);
getch(); /* Holding output */
}
Output of the above program :
Enter your name: Ramesh Bhandari ↲ Hello Ramesh Bhandari, Have a nice day. Note: ↲ indicates enter is pressed.