how can I use getline function in c?

331 views Asked by At

I am trying to use getline() function. I am using correct syntax I guess and also I have included #include<stdio.h> header file also. Still it is showing that [Error] 'getline' was not declared in this scope

here is my code

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    char *str;
    int bytes_read;
    int size=10;
    printf("please enter a string");
    str=(char *)malloc(size);
    bytes_read=getline(&str,&size,stdin);
    puts(str);
}
1

There are 1 answers

0
Ali Ghelichkhani On

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

You'll need to define the feature macro _GNU_SOURCE in order to make it available for your code.

#define _GNU_SOURCE