I was just experimenting and wondered why my attempt did not work (the program crashes).
#include <stdio.h>
#include <stdlib.h>  
int main(int argc, char **argv)
{
    
    char *list;
    list =  (char*)malloc(sizeof(char));
    char a;
    int i = 0;
    
    while ( (a =getchar()) !='\n'){
        
        list[i]= a;
        list = (char*)realloc(list,sizeof(char));
        ++i;
       
    } 
    
    printf("%s",list);
    free(list);
    
    
    return 0;
}