A better (but slower) way to get the desired result of gets() without causing buffer overflows is to use dynamic allocation like this:

char *s = NULL;
size_t len = 0;
int c;

while( (c=getchar()) != EOF && c != '\n' ) {
	s = realloc( s, ++len );
	s[len-1] = c;
}
s = realloc( s, len+1 );
s[len] = 0;
...
free( s );

(see also: malloc abuse)