I'm writing a program which creates vectors [x,y,z] from numbers loaded from my simple file, the numbers are separated just by the space. I have a problem with creating new objets using Strtok() method. Here is the code.
#include "FileStaff.h"
vector<Vector>& FileStaff::readFile(string tekst)
{
vector<Vector> main;
string buffor;
char *text;
ifstream infile(tekst, ios::in);
//Checking if file exists
if (!infile.good()) {
cout << "cannot open the file!";
return main;
}
while (!infile.eof())
{
text = paraseStringToChar(tekst);
pushingToVector(main, text);
}
infile.close();
return main;
}
Method which creates wektors and pushes them into Vector.
void FileStaff::pushingToVector(vector<Vector>& main, char * tekst)
{
Vector *wektor = new Vector[1000000];
char korektor[] = " ";
float helpTab[3];
int wordCount=0;
char * container = strtok(tekst, korektor);
//counting numbers in our array
while (container != NULL)
{
container = strtok(NULL, " ");
wordCount++;
}
for (int i = 0; i <wordCount;i++ )
{
//Creating vectots [x,y,z]
container = strtok(tekst, korektor);
helpTab[i % 3] = atof(container);
container = strtok(NULL, korektor);
if (i % 3 == 0) {
Vector wektor(helpTab[0], helpTab[1], helpTab[2]);
main.push_back(wektor);
}
}
}
If anyone could help me, I would be greatful.