Q:

How to make a dynamic char?

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

void generarCadena(char *);
void generarDimension(int, void **, int);
void reallocarDimensiones(int , void **, int);

int main(void){
    char *caracter=NULL;
    generarCadena(&caracter);
    printf("%d", sizeof(caracter));
    printf("%s", &caracter);//I want to now why this doesn't print
    return 0;
}

void generarCadena(char *scaneado){
    unsigned int cont;
    char lector;
    generarDimension(1,&scaneado,sizeof(char));
    cont = 0;
    while(!scanf("%s", &scaneado)){
        while((strcpy(lector,getchar())) !='\n' && lector!=EOF){
           reallocarDimensiones(1,&scaneado[cont],sizeof(char));
           cont++;
        }
    }
    printf("%s", &scaneado);/*Inside de function it prints, 
    however, it doesn't print outside it*/
}//This function is for the dynamic char

void generarDimension(int bloques, void **ptr, int tamanho){
    *ptr = malloc(bloques * tamanho);
    if(*ptr==NULL){
        printf("No se pudo almacenar memoria\n");
    }
}//This function mallocs any given pointer
void reallocarDimensiones(int bloques, void **ptr, int tamanho){
    *ptr = realloc(*ptr,bloques * tamanho);
    if(*ptr==NULL){
        printf("No se pudo almacenar memoria\n");
    }
}//This function reallocs any given pointer

Hi, I want to now how to dynamically store a char while writting it on the keyboard, so I made a function for it. I want to send a char pointer in it, but it doesn't seem to modify it. Another problem I have is that my function only stores a few data, so if the data is to long, my program crashes.

A:

This simplifies the code to one function to capture input until a newline. Memory is allocated on each character.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

char *generarCadena(char *);

int main(void){
    char *caracter=NULL;//so realloc will operate as malloc on first call
    caracter = generarCadena ( caracter);
    printf("%zu\n", sizeof(caracter));
    if ( caracter) {//something was input
        printf("%s\n", caracter);
        free ( caracter);
    }
    return 0;
}

char *generarCadena(char *scaneado){
    char *temp = NULL;
    int in = 0;
    size_t size = 0;

    while ( '\n' != ( in = getchar ( ))) {//loop until newline
        if ( NULL == ( temp = realloc ( scaneado, size + 2))) {//realloc for each character input and '\0'
            fprintf ( stderr, "realloc problem\n");
            return scaneado;
        }
        scaneado = temp;
        scaneado[size] = in;//set input
        scaneado[size + 1] = '\0';//terminate
        size++;
    }
    return scaneado;
}

