I have written a function to wrap GNU getline() and remove the trailing newline, but for some reason it has no effect. Am I doing something wrong?
ssize_t readline(char **lineptr, FILE *stream)
{
size_t len = 0; // Size of the buffer, ignored.
ssize_t chars = getline(lineptr, &len, stream);
if((*lineptr)[chars] == '\n') {
(*lineptr)[chars] = '\0';
--chars;
}
return chars;
}
It compiles and links without problems, but the newline is not replaced with a null-terminator. I've verified the if() statement is running. Thanks for any help!