Hello,
In a C program writen with Code::Blocks 13.12, I try to use the getline() function, but the compiler send an error undefined reference to 'getline'
(I put #include <stdio.h> in my header).
Here is my test 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
it work on linux
# gcc test.c -o test
# ./test
Saisir une ligne de texte :
vxcvxcv
Saisie de 8 caractères : vxcvxcv
Both getline() and getdelim() are GNU extensions. They are available
since libc 4.6.27.