1 Attachment(s)
Trouble reading from file?
Hi all,
I have built on the file Kurt helped me with, it is supposed to write values out to a file after the list is modified (which it does), but will not read/assign properly from the written file. To give you an example, one of my files from which I read has a, b, c, d, and e written to it, but on separate lines. When I read from the file, I also cout the values as they are read, to try to figure out where it goes wrong, and it reads a, b, c, and stops, then when I try to assign them to the info portion of the nodes, it does no assigning at all. I'm so close to being done, could someone clue me in on what is going wrong here?
Thanks!
-Patrick
.cpp code attached, but most relevant function below
listFromFile function:
__________________________________________________ ______________
Code:
void linkedList::listFromFile(ifstream& inputFile)//get node->value for all nodes from chosen file
{
char valPortion[255];
string valuePortion;//value to be put into node->value for all nodes
for(int iTwo = 1; iTwo <= 5; iTwo++)
{
(getline(inputFile, valuePortion));//while eof marker not found in file, read until
iTwo++;
cout << valuePortion;
strcpy(valPortion, valuePortion.c_str());//char *valPortion = strdup(valuePortion.c_str()) copy line from file into valPortion, which will be put into new node
//linkedListNode node(valPortion);//create node w/value = line of text
//add(node, iTwo);//add the above-created node to list
linkedListNode node(valPortion);//access node to be deleted(overwritten)
add(node, iTwo);
}
}
Whole .cpp file attached