gets, puts

The gets() function reads string from user and puts() function prints the string. Both functions are defined in <stdio.h> header file.
Let's see a simple program to read and write string using gets() and puts() functions.
  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. void main(){  
  4.     char name[50];  
  5.     clrscr();  
  6.     printf("Enter your name: ");  
  7.     gets(name); //reads string from user  
  8.     printf("Your name is: ");  
  9.     puts(name);  //displays string  
  10.     getch();  
  11. }  
Output:
Enter your name: Sonoo Jaiswal
Your name is: Sonoo Jaiswal

No comments:

Post a Comment