Here is a path that no one else has suggested that doesn't use fscanfso that you can have the correct error handling:
char buffer[BUFSIZE];
size_t size = 5;
int *data = malloc(size * sizeof *line);
if(line == NULL) error();
while(fgets(buffer, sizeof buffer, fp)
{
size_t i = 0;
char *next = buffer;
while(*next && *next != '\n')
{
data[i++] = strtol(next, &next, 0);
}
}
, , *scanf "%d" , , () : strtol. *scanf , , " " , strtol , , .
- . :
i == size, data realloc. , , , , .fgets (, '\0' '\n'). , , . - , , - fgets, , . ( fgets.)- - , .