+ 3
C getline not working
Hi, I have the following c code that just prints user input: https://code.sololearn.com/cK86CyI281gH/?ref=app It runs perfectly fine on my computer (I compiled it with gcc), but sololearn's compiler warns for an implicit declaration of getline and it doesn't ask the user for input. What's the problem?
1 Odpowiedź
+ 1
getline is not a standard C function but POSIX. You need a feature test macro to include getline:
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
That will get rid of the warning since Sololearn uses the glibc C implementation. But it won't matter much because 'getline' does not trigger an input prompt.
Better stick with fgets to read a line.