Problem statement:
I need to input text from a file into a char array, split the char array at points defined by a delimiting character, and store the sub arrays in a struct ultimately.
The text in the file is formatted like this:
Author: Publisher: Title: Comment | key1 | key2 | key3'\n'
The '|' are the important delimiters, I may use the colons to split for display purposes later.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
song ts;
ifstream fin;
for(int i = 0; i < 4; ++i)
{
ts.info[i] = new char[max];
}
char * temp = new char[max];
fin.open("datafile.txt");
if(fin)
{
fin.get(temp, max, '\n');
fin.ignore('|', '\n');
while(!fin.eof())
{
fin >> temp;
fin.ignore('|', '\n');
fin.get(temp, max, '\n');
fin.ignore('|', '\n');
}
}
else
{
cout << "File open failed!! \n";
}
|
I have to use char arrays and <cstring>- no vectors, strings, etc.
The struct will ultimately be fed into another object- in this file, I will want to loop, overwriting the struct with each new line.
I don't really understand how to manipulate the temp char array to get just the the substrings I need into the struct, but more importantly, I'm not really clear on what's happening as far as getting the text from the file into the temp array.
Any help, advice, and explanations are both sorely needed and much appreciated!