Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where/how to get the "getline" function if it is missing from stdio.h?

I'm writing a program in C using Code::Blocks 13.12 on Windows 8 (the C compiler is mingw32-gcc). I would like to use the "getline" function but it seems to be missing from the stdio.h. Is there any way to get it except for writing own implementation?

like image 589
Blackstar Avatar asked Dec 09 '14 14:12

Blackstar


2 Answers

getline is a POSIX function, and Windows isn't POSIX, so it doesn't have some POSIX C functions available.

You'll need to roll your own. Or use one that has already been written.

like image 69
rubenvb Avatar answered Oct 21 '22 07:10

rubenvb


getline is not a standard C library function. Some implementations (such as gcc) provide it as an extension.

If you're compiling with gcc, you'll need to define the feature macro _GNU_SOURCE in order to make it available for your code:

#define _GNU_SOURCE
#include <stdio.h>
...
getline (...);

EDIT

Hopefully since mingw is a GNU compiler, this should be available for you on windows.

like image 23
John Bode Avatar answered Oct 21 '22 06:10

John Bode