冗長すぎ。これで十分
int strsize = 1,strpos=0;
char *str = NULL;
do{
    char *tmp = (char *)realloc(str, strsize *= 2);
    if(tmp==NULL) { free(str); exit(1); }
    str = tmp;
    if(fgets(str+strpos, strsize-strpos, stdin) == NULL)break;
    strpos += strlen(str+strpos);
}while(str[strpos-1] != '\n');
puts(str);
free(str);