Professional Documents
Culture Documents
18 Jan 2024 Lecture PF - Regrow 1D Array - 1
18 Jan 2024 Lecture PF - Regrow 1D Array - 1
system("pause");
return 0;
}//end of main
void diplay_array(int* aptr, int s)
{
for (int i = 0; i < s;i++)
{
cout << aptr[i] << endl;
}
}
void read_file(int* myarray, char* fn, int fsize)
{
ifstream fin;
fin.open(fn);
for (int i = 0; i < fsize; i++)
{
fin>> myarray[i];
}
}
int calculate_fileSize(char* fname)
{
fstream fin;
int c = 0;
int temp; //this temporary variable declared will
accept /recieve the array elements one by one
fin.open(fname);
while (fin>>temp)
{
c++;
}
return c;
int main()
{
char filename[20] = "mydata.txt";
int* data = NULL;
int size = 0;
int num = 0;
ifstream fin;
fin.open(filename);
fin >> num;
data = new int[1]; //one memory cell of 4 bytes
resereve
data[0] = num;
cout << "------------------ : " << data[0] << endl;
size++; // first memory cell is gain so increase
the size of new created arrray
while (fin >> num)
{
data = Regrow1D(data,size,num);
size++;
}
}//end of main
void copyArray(int* newarray,int* oldarray,int s)
{
for (int i = 0; i < s;i++)
{
newarray[i] = oldarray[i];
}//end of for
}