Re: reading text file with MFC solution
- From: "Dan" <dn@xxxxxxxxx>
- Date: Tue, 22 Jul 2008 15:12:19 +0300
No error checking and probably with some "off by 1" errors but this is what
I came up with. Any comments are welcome. Thank you!
CStdioFile stdFile;
CFileException CFileEx;
if(!stdFile.Open(_T("C:\\products.txt"), CFile::modeNoTruncate |
CFile::modeRead| CFile::modeCreate, &CFileEx))
{
CString strLine;
CString strBarCode;
CString strName;
CString strQty;
CString strPrice;
while (stdFile.ReadString(strLine))
{
if (strLine.GetLength() == 0)
continue;
strLine.Trim();
int iPos = strLine.Find(_T(' '), 0);
int i = 0;
if (iPos != -1)
{
for (i = 0; i < iPos; ++i)
strBarCode += strLine.GetAt(i);
}
int iEndOfBarcode = i;
int iWhiteSpace = strLine.ReverseFind(_T(' '));
int iLineLength = strLine.GetLength();
for (i = iWhiteSpace+1; i < iLineLength; ++i)
strPrice += strLine.GetAt(i);
while (strLine.GetAt(iWhiteSpace) == _T(' '))
--iWhiteSpace; // get to end qty
int iEndQty = iWhiteSpace;
while (strLine.GetAt(iWhiteSpace) != _T(' '))
--iWhiteSpace; // get to begin qty
int iBeginQty = iWhiteSpace;
for (i = iBeginQty; i < iEndQty; ++i)
strQty += strLine.GetAt(i);
while (strLine.GetAt(iBeginQty) == _T(' '))
--iBeginQty; // get to the end of product name
while (strLine.GetAt(iEndOfBarcode) == _T(' '))
++iEndOfBarcode; // get to beginning of product name
for (int i = iEndOfBarcode; i < iBeginQty; ++i)
strName += strLine.GetAt(i);
}
}
stdFile.Close();
Dan
.
- Follow-Ups:
- Re: reading text file with MFC solution
- From: Joseph M . Newcomer
- Re: reading text file with MFC solution
- References:
- reading text file with MFC
- From: Dan
- Re: reading text file with MFC
- From: Dan
- reading text file with MFC
- Prev by Date: Detect internet connection via VC++
- Next by Date: Re: reading text file with MFC
- Previous by thread: Re: reading text file with MFC
- Next by thread: Re: reading text file with MFC solution
- Index(es):
Relevant Pages
|