User forums > Using Code::Blocks
C getline() seem not working !?
(1/1)
lucrol:
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'
--- End quote ---
(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;
}
}
--- End code ---
What's the matter ?
Bests regards.
Luc
turbosnail:
it work on linux
--- Code: ---# gcc test.c -o test
# ./test
Saisir une ligne de texte :
vxcvxcv
Saisie de 8 caractères : vxcvxcv
--- End code ---
--- Quote ---Both getline() and getdelim() are GNU extensions. They are available
since libc 4.6.27.
--- End quote ---
lucrol:
--- Quote ---it work on linux
--- End quote ---
Yes, but don't works on Windows ! (C::B v13.12)
Need a specific Library ?
BlueHazzard:
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
Navigation
[0] Message Index
Go to full version