Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: lucrol on December 11, 2014, 03:41:11 pm

Title: C getline() seem not working !?
Post by: lucrol 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
/* 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
Title: Re: C getline() seem not working !?
Post by: turbosnail on December 11, 2014, 05:37:58 pm
it work on linux
Code
# 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.
Title: Re: C getline() seem not working !?
Post by: lucrol 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 ?
Title: Re: C getline() seem not working !?
Post by: BlueHazzard 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