gets-in-c

Learn C - C tutorial - Gets in c - C examples - C programs

C - gets() - Definition and Usage

  • In C- Programming gets is similar to scanf statement which is used to scan a line of text from a standard input device.
  • The gets () function will be terminated by a newline character.
  • The newline character won't be included as part of the string.
  • The string may include white space characters.
C Gets

C Syntax

char *gets(char *s);

Sample coding - Gets

#include<stdio.h>
#include<conio.h>
void main()
{
    char *str;
    clrscr();
    printf("Enter a string \n");
    gets(str);
    printf("Given String is %s " ,str);
    getch();
}

C Code - Explanation

code-explanation-gets
  1. Here we are declaring the character array in the variable name “str”.
  2. In this statement we are getting the character value using getstring function and the value will be stored in the variable “str”.
  3. In this print statement we are printing the given string value by calling the variable “str”.

Output :

gets-sample-output
  1. Here the entered string “welcome to wikitechy” has been shown in the console window.
  2. And using the printf statement we display the statement “Given String is welcome to wikitechy” .

View More Quick Examples


Related Searches to c gets