Can someone help me with this code from C lesson 4 getchar() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone help me with this code from C lesson 4 getchar()

#include <stdio.h> int main( ) { char a[100] gets(a) ; printf("You entered: %s" , a); return0; } The answer I always get from this code is below ./Playground/file0.c:Infunction 'main': /Playground/file0.c:6:5: warning: implicit declaration of function 'gets' ; did you mean 'fgets'? [-Wimplicit-function-declaration] 6 | gets(a) ; | ^~~~ | fgets ../Playground/: /tmp/cc6BjXm0.o:in function 'main': file0.c: (.text+0×15): warning: the 'gets' function is dangerous and should not be used.

30th Nov 2021, 11:35 AM
Sidian
Sidian - avatar
4 Answers
30th Nov 2021, 2:10 PM
Solo
Solo - avatar
+ 2
This is because gets () has been deprecated years ago from the language standards. It's much better to follow your compiler's instructions and use fgets () instead.
30th Nov 2021, 12:07 PM
Arsenic
Arsenic - avatar
+ 1
Sidian are you sure, you are using fgets () correctly ? Check out cppreference for correct usage 👇 https://en.cppreference.com/w/c/io/fgets If still the program gives some kind of error/warning then it is recommended to post the new code for further troubleshooting.
30th Nov 2021, 1:46 PM
Arsenic
Arsenic - avatar
0
I tried fgets but I got the same output
30th Nov 2021, 12:31 PM
Sidian
Sidian - avatar