I have to read a text based data file, with an unknown number of data points, into an array in C, but I can't work out how to do this. I can't even manage to get my program to successfully open the text file, let alone put it into an array etc
The file contains numerical values, so it is not a string it needs to be read into. Ideally this should be done by the user inputting the file name.
I basically need the program to:
- Ask user to input file name (I understand this is just a simple printf job)
- When the user inputs the file name, the program opens the text file, stores the data from it into an array of an appropriate size.
- Print entire array to show that this has been done.
If anyone could give a step to step explanation of how this can be done I would really appreciate it.
fscanffunction to read numbers, and thereallocfunction to reallocate array in the RAM.