First let me tell you what my program is doing. its basically a shopping list program. Whereby the user will input the values and it is then inserted into a text file. There will be 3 inputs (Item Description,Unit Price,Quantity Purchased) and is stored into the text file as (Shoes:$200:2) but when i try to call out the string it is shown as
Item 1
Item Description: Shoes:$200:2
Unit Price:
Quantity Purchased:
I know i need to use the getline() and use a delimiter but i dont know how to put it in my code.
int txtTArrayTrans (fstream& infile, char filename[], StoreTransDetail trans[])
{
infile.open (filename, ios::in);
if (!infile.good())
{
cout << filename << " open for reading failed" << endl;
exit(1);
}
else
{
}
char p[MAXSTR];
int count = 0;
int pos = 1;
while (!infile.eof())
{
while (infile >> p)
{
if (pos == 1)
{
strcpy(trans[count].item,p);
}
if (pos == 2)
{
trans[count].unitPrice = p[0] - '0';
}
if (pos == 3)
{
trans[count].quantity = p[0] - '0';
}
pos += 1;
}
infile.close ();
return count;
}
}
void editTrans(StoreTransDetail trans[])
{
int transSize;
fstream infile;
fstream outfile;
int editItem;
char item[MAX];
int unitPrice;
int quantity;
transSize = txtTArrayTrans (infile, "StoreTransDetail.txt", trans);
infile.close();
for (int i=0; i<transSize; i++)
{
cout << "Item " << i+1 << ")" << endl;
cout << "Item Description :\t" << trans[i].item << endl;
cout << "Unit Price :\t" << trans[i].unitPrice << endl;
cout << "Quantity Purchased :\t" << trans[i].quantity << endl;
}
cout << "Item to be edit: ";
cin >> editItem;
cout << "Item Description: ";
cin >> item;
cout << "Unit Price: ";
cin >> unitPrice;
cout << "Quantity Pruchased: ";
cin >> quantity;
editItem--;
strcpy(trans[editItem].item,item);
trans[editItem].unitPrice = unitPrice;
trans[editItem].quantity = quantity;
ArrayTtxtTrans (outfile, "StoreTransDetail.txt", trans, transSize);
outfile.close();
}