Я работаю над программой, которая читает некоторые данные из файла, отформатированного так:
21
285 270 272 126 160 103 1
31
198 180 163 89 94 47 1
32
240 230 208 179 163 104 1
33
15 13 12 14 15 15 0
34
63 61 62 24 23 20 2
Я пытаюсь прочитать первое число в один массив указателей, а остальные 7 чисел - впараллельный массив двумерных указателей, но по какой-то причине каждый раз, когда я запускаю свой код, он просто перестает работать.Это не возвращает ошибку, но я чувствую, что мое использование указателя неправильно, потому что я впервые использую указатели.Файл данных называется "lection_data_121.txt ", к вашему сведению.Вот код.Если бы кто-нибудь мог взглянуть, я был бы так благодарен:
#include <iostream>
#include <fstream>
using namespace std;
//bool openFileIn(fstream &, char *);
int main()
{
const int PREC_SIZE = 30;
const int CANIDATES = 7;
int *precinct_num[PREC_SIZE];
int *num_votes[PREC_SIZE][CANIDATES];
cout << "Declarations made." << endl;
fstream dataFile; //Make a file handle
cout << "File object made." << endl;
//Open the file and check that it opened correctly
if(!openFileIn(dataFile, "election_data_121.txt"))
{
cout << "File open error!" << endl;
return 0; //Exit the program
}
cout << "File opened." << endl;
//Read the contents of the file into the proper arrays
int counter = 0;
while(!dataFile.eof())
{
dataFile >> *precinct_num[counter];
for(int i = 0; i < 7; i++)
{
dataFile >> *num_votes[counter][i];
}
counter++;
}
//Print out the data
for(int j = 0; j < counter; j++)
{
cout << *precinct_num[j];
for(int i = 0; i < 7; i++)
{
cout << *num_votes[j][i];
}
}
dataFile.close();
cout << "End of file";
return 0;
}
bool openFileIn(fstream &file, char *name)
{
file.open(name, ios::in);
if(file.fail())
return false;
else
return true;
}
Еще раз спасибо!