Home » C programs » stdio.h header file functions

gets() function of stdio.h in C

In this article, we are going to learn about the gets() function of stdio.h header file in C programming language, and use it get string and then print it on console.
Submitted by Abhishek Sharma, on April 12, 2018

The function gets() is used to scan a string from the user without any \n or till the \n character. This function is from the string.h class doing the jobs related to strings.


    gets(str) ;
    User input: "I AM A STRING"


You can also use scanf() which shave more options then this function.

stdio.h - gets() function Example in C

#include <stdio.h>

int main () 
	//initializing the type of variables
	char str[50];
	char c;

	//message for user
	printf("Please enter a string : ");

	//printing the result
	printf("Your String: %s\n\n", str);

	//message for user
	printf("Please enter a character: ");
	c = getchar();

	//printing the result
	printf("Your Character: ");



stdio.h - gets() in c language

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com (2015-2018), Some rights reserved.

close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.