I think what you are looking for is realloc()
When you have reached the pointer limit of what you have allocated you can add more pointers.
e.g.
size_t rows = 10;
char** data = malloc( sizeof(char*) * rows );
size_t row = 0;
...
tmp = get_next_line(0);
if ( ++row == rows )
{
row = 0;
rows += 10;
char** expanded = realloc( data, sizeof(char*) * rows );
if ( expanded != NULL )
{
data = expanded;
}
// else error
}
data[i++] = tmp;
...
A side note:
It looks like you overwrite the last string when you do
while (b != 1) {
while (strcmp(next, tmp) != 0) {
printf("> ");
tmp = get_next_line(0);
data[i++] = tmp;
}
data[--i] = 0; <---- maybe you meant `data[i]=NULL;`