DISCLAIMER: I'm new to C.
What is the best way to convert every line in a .txt file (can be other file types too) to a dinamic calloc() array, and the other way around?
In my file I have to following:
1 Hello
2 18
3 World
4 15
etc...
I want something like this in the array:
[0] Hello
[1] 18
[2] World
[3] 15
etc...
The code i have now:
FILE *file;
file = fopen("test.txt", "r");
int i = 0;
//make dynamic calloc array
//while line!= EOF
//put line[i] into array
//i++
//realloc array, size +1
fclose(file);
Is this way of doing this a good one or is there a better one? If someone could help me a little bit with the code I would be really thankful.