I'm trying to create a function that manipulates an 2d array read from a text file. So the dimensions vary depends on the file size, which is found in another function.
My question is how to pass this 2d array without stating the size in the parameter.
void create(char** arr, fstream&in, int r, int c) //create array according to file
{
in.clear();
in.seekp(0, ios::beg);
char cha;
cout<<r<<" by "<<c<<endl;
arr=newchar*[r];
for(int i=0; i<r; i++)
{
arr[i] = newchar[c];
for(int j=0; j<c; j++)
{
in.get(cha);
if(cha=='\n') //when get to end of line in file
{
in.get(cha);//skip to next character
}
*((*(arr+i))+j)=cha;//stores charater to each cell
cout<<*((*(arr+i))+j);//prints out each cell
}cout<<endl;
}
}
This function creates the array, which works fine.
but when I write another function that access the array and display it, it crashes. (I know I have display inside the create function, but this is just practice so I know how to write a manipulative function with the array)