Gets | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Gets

What us gets used for gets()

4th Apr 2021, 5:55 AM
Surya L
Surya L - avatar
9 Answers
+ 6
Do NOT use the gets() function. It is unsafe and was removed from the standard a long time ago. When you use gets() the compiler gives you a warning also. Instead use the fgets() function https://www.cplusplus.com/reference/cstdio/fgets/
4th Apr 2021, 6:11 AM
XXX
XXX - avatar
+ 3
@Martin Taylor To be fair though, the SoloLearn course itself shows the gets() function without even mentioning that it is not a part of the standard anymore and that it should not be used. gets() function has literally been used a lot of times in the example codes throughout the course. What makes it worse is that fgets() isn't even mentioned once in the course. As the OP has completed only 7% of the C course on SoloLearn, I think they came to know about it from there.
4th Apr 2021, 1:56 PM
XXX
XXX - avatar
+ 1
in which language?
4th Apr 2021, 6:00 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 1
C
4th Apr 2021, 6:00 AM
Surya L
Surya L - avatar
+ 1
gets() reads a line from stdin and stores it into the string pointed to by str.
4th Apr 2021, 6:01 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 1
K
4th Apr 2021, 6:02 AM
Surya L
Surya L - avatar
+ 1
Ok
4th Apr 2021, 6:12 AM
Surya L
Surya L - avatar
0
In java get() and set() methods are used for private methods to set the value and print the value
4th Apr 2021, 12:19 PM
venkat reddy