У меня есть файл с одной записью на строку (имя, имя, id #, оценка, оценка, оценка, оценка, оценка, оценка)
Я должен подтвердить в соответствии с 64 цифрами или менее: имена, ID: 9 цифр и 0 <класс <100.
Я хочу сохранить в tempArray [9], проверить, затем сохранить в realArray [9] [200]. Я думаю, что моя главная проблема, когда я пытаюсь хранить. </p>
tempArray был протестирован почти везде с std::cerr << tempArray[i] <<std::endl;
и содержит правильные данные.
НО realArray также был протестирован и содержит только первую запись. Я передаю realArray следующим функциям, так что когда я получаю storeData, я могу передать tempArray в realArray с маркером столбца в соответствии с lineNumber.
Я ЗНАЮ, ЧТО ЯВЛЯЮТСЯ ВЕРОЯТНЫМИ ТОННЫМИ ошибок и программирования "НЕ ДЕЛАЙТЕ", но мне нужно знать
1) если то, что я пытаюсь сделать, можно сделать
2) Почему мой realArray получает только первую запись.
/ Добавлено после: я знаю, что оно не сохраняется в realArray, потому что моя переменная приращения - const int
. но тогда для меня не имеет смысла, почему он принимает на хранение первую запись. это потому, что номер строки инициализируется нулем?
если storeData принимает lineeNumber в первый раз, почему он не делает это в течение второго? /
код:
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include "A4prototypes.h"
#include "search.h"
#include "sort.h"
using namespace std;
void getFile(std::string realArray[][200], const int ROWS)
{
std::string filename, line, token;
int row(0);
int lineNumber(0);
const int MAX_RECORDS (200);
const int TEMP_ROWS(9);
const int ZERO(0);
std::string tempArray[TEMP_ROWS];
std::cout << "Please enter the desired filename with it's extension:\t ";
std::cin >> filename;
std::ifstream input(filename.c_str(), std::ios::in);
if (input.is_open())
{
getline (input,line);
while (input.good() && lineNumber < MAX_RECORDS)
{
std::istringstream inputss (line);
while (getline(inputss, token, ',') && row < ROWS )
{
tempArray[row] = token;
row++;
}
row = ZERO;
/*I know I don't need to send the rows size of both of these arrays, but ... */
validateData (lineNumber, tempArray, TEMP_ROWS, realArray, ROWS);
lineNumber++;
getline (input,line);
}
}
else
{
std::cout << "The file did not open correctly. \n\nPlease enter a valid filename.\n";
}
if (lineNumber == MAX_RECORDS)
{
std::cout << "The maximum number of records to be read (" << MAX_RECORDS << ") has been reached.\n";
}
}
void validateData (int lineNumber, std::string tempArray[], const int ROW, std::string realArray[][200], const int ROWS)
{
int j(0);
//Validate Data functions...
// Pass tempArray and realArray along with lineNumber to update realArray.
storeData(lineNumber, tempArray, ROW, realArray ,ROWS);
}
int storeData(int record, std::string tempArray[], const int ROWS, std::string realArray[][200], const int ROW_SIZE)
{
int k(0);
std::string tempstr;
record-=1;
for (k; k < ROWS; k++)
{
tempstr = tempArray[k].data();
realArray[k][record]=tempstr;
}
return 0;
}
int main ()
{
/* There should be a pointer here that gets sent to getFile and incriminates with the record line, gets sent to store data and the
rest instead of just lineNumber,????...*/
int i(0), j(0);
const int ROWS(9);
const int COLUMNS(200);
/* int * const rows = &ROWS; => It says in the book you can do this and pointer isn't const, but you could do *rows =10, which is what I want to
do with the column, but it wont work... */
std::string realArray[ROWS][COLUMNS]={}; // Declare array for storing the data once it's been validated so I don't keep unecessary data.
// Pass realArray to getFile so I can have access to it from main but it can be changed by getFile was the plan so fn's dont have to all be related to main.
getFile(realArray,ROWS);
return 0;
}
А вот и заголовочный файл
#ifndef _h
#define _h
void getFile(std::string [][200], const int);
void validateData (int,std::string [], const int, std::string [][200], const int);
int storeData(int, std::string [], const int, std::string [][200], const int);
#endif