No, that won't work. If you don't want to use realloc then you'll have to read the file twice. The first time you count the number of lines. Then you malloc that many char*'s for a char** array. Then read the file again and do something like what you're doing. In the code you've posted you've also used counter incorrectly (it doesn't represent the number of chars you want to malloc).
Code:
int main(void) {
FILE *fp;
char buffer[256];
char **names, *p;
int nlines = 0;
/* TODO: read file and count lines */
names = malloc(nlines * sizeof(char*));
/* TODO: test that malloc succeeded */
rewind(fp);
nlines = 0;
while (fgets(buffer, sizeof(buffer), fp)) {
if ((p = strchr(buffer, '\n')) != NULL)
*p = '\0'; /* remove newline character */
names[nlines] = malloc(strlen(buffer) + 1);
/* TODO: test that malloc succeeded */
nlines++;
}
fclose(fp);
/* TODO: do something with the lines */
/* TODO: Free everything */
return 0;
}