School task Read from file and create pointer based array of integers
Hi Guys,
I have one more school task to finish an I need some help understanding where should I start from.
The task is as follows:
"02 - You have been provided with a text file Vals.txt containing some integer numbers. Create a class named A02.c that opens the text file, reads the integer values and dynamically creates a pointerbased array of integers. You should not assume a fixed length but rather dynamically allocate memory. Make sure to appropriately dispose of the variable prior to ending the application."
I already did the code to open the file:
Code:
#include <stdio.h>
int main()
{
FILE *fp;
fp = fopen("vals.txt","r");
while( fscanf(fp,"%d",&temp) != EOF )
{
}
}
But i need to do this "dynamically creates a pointerbased array of integers. You should not assume a fixed length but rather dynamically allocate memory."
Could you please give me a code example on how to do it?
I already searched google but can't find anything close to what I need.
Any help is greatly appreciated.