Working on a program for a friend of mine to change a .txt file. I was hoping to get some advice on my program as I seem to always end up in an infinite loop while I'm printing out the data. Here's what I have so far:
#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
int count=0;
ifstream myFile;
myFile.open("data.txt");
while(!myFile.eof()) //open file to get count
{
myFile.get();
count++;
}
myFile.close();
int **marina = newint *[count];
for(int z=0;z<count; z++)
{
marina[z] = newint [14];
}
myFile.open ("data.txt"); //had to reopen file to read into
for(int i=0; i<count;i++) //array
{
for(int c=0;c<14;c++)
{
marina[i][c] = myFile.get();
}
}
myFile.close();
for (int b=0;b<count;b++) //This is the problem, when trying to see what the data
{ //looks like by cout it so I can manipulate it
for(int y=0;y<14;y++) //I end up in a infinite loop
{
cout << marina[b][y];
}
}
return 0;
}
Looking for any advice, this is my first time working with 2d dynamically allocated arrays.
I'm trying to make the dynamic array that is [count][14] since the count variable is unknown but the amount of columns is 14. I was trying to figure out how to do the 2d array dynamically since I haven't learned vectors or anything that might make it easier. Hope that clarifies what I'm trying to do, as far as the code that's why I was asking.