#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int inputAsingleChar,i=0,j=4;
    char *name = malloc(j);
    if (name == NULL){
        printf("No memory");
        exit(1);
    }
    printf("Your name: \n");
    while((inputAsingleChar = getchar()) != '\n' && inputAsingleChar != EOF)
    {
        if(i==j){
            j+=4;
            char * tmp = realloc(name, j);
            if(tmp== NULL){printf("Couldn't realloc but the 'name' array is still valid");}
            else{name = tmp;}
        }
        name[i++] = inputAsingleChar ;
    }
    name[i] = '\0';
    printf("Name: %s  \n", name);
    free(name);
    return 0;
}