Effective Way to use gets function

0 Suresh Chand June 2, 2021

In this function, We will learn to use gets function in the c programming language. To understand this example, You must have knowledge of the following topics.

Download Application: Learn C Programming with Live Compiler

Her are some facts you must now about the scanf() and gets().

  • scanf() and gets() boths are used to take input from user
  • scanf() takes inputs and it ignore after space
  • gets() takes input with space and it ignore after line break

Algorithm

This is the algorithm to use gets function

Step 1: Start

Step 2: Initialize array variable of size 50

Step 3: Use gets() function and pass initialized variable as parameter

Step 4: Print String variable

Step 5: End

Flowchart

This is the flowchart to use gets() functions in effective way

Flowchart : Effective Way to use gets function

Now, Let’s look an code to understand how to use gets() in c programming language.

#include<stdio.h>

int main()
{
    // char array of size 50
    char str[50];

    printf("Enter your full name:\n");

    gets(str);
    
    printf("\nYour Name is :  %s", str);

    return 0;
}

Download Application: Learn C Programming with Live Compiler

The output of above program is

Enter your full name:
Suresh chand

Your Name is :  Suresh chand

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

!

Ads

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System