line 77: >> fin.getline(description, 25);
Unfortunately that doesn't work because the description field is not a fixed size of 25 characters in the data file. What you need to do is just read the next two words and concantinate them together: something like this
std::string temp;
fin >> nnptr->description;
fin >> temp; temp = " " + temp;
strcat(nnptr->description, temp.c_str();
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
getline() reads 25 charcters, or up to end-of-line, which ever is shorter. In order for that to work the description field in the data file must always be 25 characters (fixed length). The newest file example you just posted has 3 words in some description fields, which tosses out my previous suggestion. Here is how I would do that NOTE: This has not been compiled or tested.
std::string line;
while( getline(fin, line) )
{
size_t pos = 0;
// find first non-digit character
while( idsigit(line[pos]) )
pos++;
// extract pid
nnptr->pid = atol( line.substr(0,pos).c_str());
line = line.substr(pos+1);
// find first digit field (end of description)
for(pos = 0; !isdigit(line[pos]); pos++)
;
// extract description
strcpy(nnptr->description, line.substr[0,pos].c_str());
line = line.substr(pos);
// convert remainint integers
strstring str(line);
str >> nnptr->wholesale >> nnptr->markup >> nnptr->quantity;
// add nnptr to linked list
<snip>
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343