> How can I know size when expecting user to enter string from keyboard?
You can't.
You always have to read from stdin using fgets() into some fixed sized buffer. If the user decides to type in a lot, then you can start calling memory allocation routines to save each fragment in say a linked list.
Code:
char buff[BUFSIZ];
while ( fgets( buff, sizeof buff, stdin ) != NULL ) {
char *p = strchr( buff, '\n' ); /* find the newline */
if ( p == NULL ) {
/* no newline, user filled the buffer */
/* copy this buff to allocated memory and */
/* repeat calls to fgets() */
} else {
/* do something with buff */
/* and/or the allocated memory containing partial input */
}
}