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() Examples

Example #1 : Reading String Using gets() Function


void main()
  char name[100];
  clrscr(); /* Clear the screen */
  printf(“Enter your name:\n”);
  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.