I can think of two basic options.
1. There is a maximum you expect from the user and will discard anything else after that:
Code:
char buffer[MAX_LEN+1]; // one extra space for the null character
char *input;
read string into buffer using fgets, scanf, etc
allocate strlen(buffer) + 1 bytes into input
copy the contents of buffer into input
2. There is no maximum, or you like causing yourself undue suffering.
Code:
char c;
char *input = malloc(1); // initial allocation so we can just realloc in our loop
int n_char = 0;
input[0] = '\0'; // null terminate input in case they enter no data
do
c = read a character
if c is not EOF
reallocate n_char+1 bytes into input
copy c onto the end of input
null terminate input
while c is not EOF
There is a third method that uses a combination of 1 and 2 so you read in, say, 1000 chars at a time to a buffer and reallocate if need be. This would be my preferred method only if option 1 is not sufficient.