array of struct read from file in C I want to read csv file in to array of structs with NULL ending.    

test.txt:

11,345,1,k
12,34.23,3,v
13,13.4,5,x
14,15.7,6,c


My code:

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

struct csv_line {
  int value1;
  float value3;
  int value2;
  char char1;
};

struct csv_line *line_pointer = NULL;

int main(void) {
    FILE *csvFile = NULL;
    csvFile = fopen("test.txt", "r");
    if (csvFile == NULL)
      exit(1);

    size_t i = 0;
    while (1) {
    line_pointer = (struct csv_line *)realloc(line_pointer, sizeof(struct csv_line) * (i + 1));
    if (fscanf(csvFile, "%d,%f,%d,%c",
            &amp;(line_pointer + i)-&gt;value1,
            &amp;(line_pointer + i)-&gt;value3,
            &amp;(line_pointer + i)-&gt;value2,
            &amp;(line_pointer + i)-&gt;char1) != EOF) {
      i++;
    } else{
        (line_pointer + i)-&gt;value1 = 0;
        (line_pointer + i)-&gt;value3 = 0.0;
        (line_pointer + i)-&gt;value2 = 0;
        (line_pointer + i)-&gt;char1 = '\0';
        break;
     }
    }
    fclose(csvFile);
    int k = 0;
    while('\0' != (line_pointer + k)-&gt;char1) {
        printf("%d, %.2f, %d, %c",
                (line_pointer + k)-&gt;value1,
                (line_pointer + k)-&gt;value3,
                (line_pointer + k)-&gt;value2,
                (line_pointer + k)-&gt;char1);
        printf("\n");
        k++;
    }

    free(line_pointer);

    return EXIT_SUCCESS;
}


Questons:


Is it possible to move fscanf condition inside while-loop condition instead of endless (1) ?
How to set "end" of array with single NULL like "line_pointer[i] = NULL" in else statement?
user3629249's answer is good. The only thing I have to add:

struct csv_line *line_pointer = NULL;

// ...

&amp;(line_pointer + i)-&gt;value1


is awkward. Why go through the pointer addition acrobatics? Why not just

&amp;line_pointer[i].value1