Author Topic: C getline() seem not working !?  (Read 10143 times)

Offline lucrol

  • Single posting newcomer
  • *
  • Posts: 2
C getline() seem not working !?
« on: December 11, 2014, 03:41:11 pm »
Hello,
In a C program writen with Code::Blocks 13.12, I try to use the getline() function, but the compiler send an error
Quote
undefined reference to 'getline'
(I put #include <stdio.h> in my header).
Here is my test code :
Code: [Select]
/* Test_getline.c : acquisition sécurisée d'une ligne de texte
*/
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int bytes_len = 80;                                 // taille de la chaîne
  int bytes_read;
  char *my_string;

  my_string = (char *) malloc(bytes_len + 1);          // +1 pour \n

  puts ("Saisir une ligne de texte : ");
  if ((bytes_read = getline(&my_string, &bytes_len, stdin)) == -1)
    {
      puts("Erreur de saisie !");
      return -1;
    }
  else
    {
      printf("Saisie de %d caractères : %s", bytes_read, my_string);
      return 0;
    }
}
What's the matter ?
Bests regards.

Luc

Offline turbosnail

  • Single posting newcomer
  • *
  • Posts: 7
Re: C getline() seem not working !?
« Reply #1 on: December 11, 2014, 05:37:58 pm »
it work on linux
Code: [Select]
# gcc test.c -o test
# ./test
Saisir une ligne de texte :
vxcvxcv
Saisie de 8 caractères : vxcvxcv

Quote
Both getline() and getdelim() are GNU extensions. They are available
since libc 4.6.27.

Offline lucrol

  • Single posting newcomer
  • *
  • Posts: 2
Re: C getline() seem not working !?
« Reply #2 on: December 11, 2014, 07:38:32 pm »
Quote
it work on linux
Yes, but don't works on Windows ! (C::B v13.12)
Need a specific Library ?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2599
Re: C getline() seem not working !?
« Reply #3 on: December 12, 2014, 12:37:10 am »
first of all: Codeblocks is not a compiler....

your question is 100% compiler (or libc) specific, and so this forum is the wrong place to post such questions.


second: http://stackoverflow.com/questions/13112784/undefined-reference-to-getline-in-c (first result at google)

greetings