Here's a working example using getline to fetch characters from the keyboard...
// example using getline
#define __STDC_WANT_LIB_EXT2__ 1
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
ssize_t chars;
char* line = calloc(10,sizeof(char));
size_t size = 10;
chars = getline(&line, &size, stdin);
printf("You typed :\n%s\n",line);
printf("%d chars, buffer is %d chars\n\n",chars, size);
free(line);
return 0;
}
(Note that line cannot be NULL and the carriage return (\n) is stored in the string before the null terminator)