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

int name(char *table, char *text)
{
    table = (char *) realloc(table, (strlen(text) + 1) * sizeof(char));

    if (table == NULL) {
        return EXIT_FAILURE;
    }

    /* O nome da tabela é copiado para "table" */
    strncpy(table, text, (strlen(text) + 1) * sizeof(char));

    return EXIT_SUCCESS;
}

int add(char *table, char *text)
{
    //table = (char *) realloc(table, (strlen(text) + 1) * sizeof(char));
    table = (char *) realloc(table, ((strlen(table)) + (strlen(text) + 1)) * sizeof(char));

    if (table == NULL) {
        return EXIT_FAILURE;
    }

    /* Os dados da tabela são concatenados */
    strncat(table, text, (strlen(text) + 1) * sizeof(char));

    return EXIT_SUCCESS;
}

int main(void)
{
    char *table = (char *) malloc(sizeof(char));

    if (table == NULL) {
        fprintf(stderr, "Erro ao inicializar o ponteiro!\n");
        exit(EXIT_FAILURE);
    }

    name(table, "Nomes:\n");

    add(table, "Lucas\n");
    add(table, "Vanessa\n");

    add(table, "Fulano\n");
    add(table, "Ciclano\n");
    add(table, "Beltrano\n");
    add(table, "Teste 123... 123...\n");

    printf("%s", table);

    free(table);

    return EXIT_SUCCESS;
}