C getline not working | Sololearn: Learn to code for FREE!


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/26/2022 7:26:42 PM

Joel Kronqvist

1 Answer

New Answer


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.