+ 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.
4 odpowiedzi
+ 2
Hope this code helps you:
https://code.sololearn.com/c20Wc4TF3n1r/?ref=app
+ 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.
+ 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.
0
I tried fgets but I got the same output