Click here to Skip to main content
15,918,050 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm reading data from a text file. and I'm using CString tokenize to detect "\t"
But whenever i run the code, it gives me an Assertion Fail error. Also, after i comment off the tokenize function and use the normal function, I cannot seem to add in text in the 2nd Column onwards. This is how i call the function in Oninit:
"ReadConfigFile();"

C++
void CGraphicPlotter1Dlg::ReadConfigFile()
{
	CString sBuf;
	meStringArray ArrLine;
	int foundAt = ArrLine.Find(searchStr);
	int endAt = ArrLine.Find(searchStr);
	int unitAt;
	int unitEnd;
	int i;
	int imgNbr = 0;

	CString Seperator = _T("\t");
	int Position = 0;
	CString Token;

	ReadFile("New Text Document.txt", ArrLine);
	int dwLength = ArrLine.GetSize();
	searchStr = "UnitY-Name";
	foundAt = ArrLine.Find(searchStr);
			
	if(foundAt != -1 )
	{	
		i = foundAt + 1;
		while( i < dwLength)
			{
				// Get Name of curves
				sBuf=ArrLine.GetAt(i);
				endAt = sBuf.Find("\t");
				resultStr = sBuf.Mid(0,endAt);
				LPSTR curveName = resultStr.GetBuffer(); // Convert from CString to LPSTR

				//Token = sBuf.Tokenize(Seperator, Position);
				//while(!Token.IsEmpty())
				//{
					// Get next token.
					//Token = sBuf.Tokenize(Seperator, Position);
				//} 

				// Get Units of curves
				unitAt = sBuf.Find(" ");
				unitEnd = sBuf.Find("\t",23);
				nextStr = sBuf.Mid(unitEnd,unitAt);

				lvItem.mask = LVIF_IMAGE |  LVIF_TEXT;

				// Insert data into ListCtrl
				lvItem.mask = LVIF_IMAGE |  LVIF_TEXT;
				lvItem.iItem = imgNbr;
				lvItem.iSubItem = 0;
				lvItem.pszText = curveName;
				lvItem.iImage = imgNbr;
				nItem = this->m_listTable.InsertItem(&lvItem);
				this->m_listTable.SetItemText(nItem, 1, nextStr);
				//this->m_listTable.SetItemText(nItem, 2, nextStr);
				//this->m_listTable.SetItemText(nItem, 3, nextStr);
				i++;
				imgNbr++;	
			}
		}
		else
		{
			AfxMessageBox("No Curves Found!", MB_ICONEXCLAMATION);
		}	
}


Any help will be greatly appreciated.
Posted
Comments
skfoo1 16-Feb-12 2:43am    
I can't seem to update my question. It keeps giving errors.

anyway, my data looks something like this:

rawf 0 0 1 1 1 0XA52A2A --

I want to extract just the "--", and the all spaces are in fact "\t".
I'm not sure whether i am going in the right direction.

i think you need insert more Column by using InsertColumn
 
Share this answer
 
Comments
skfoo1 16-Feb-12 3:37am    
Oh yea! I overlooked it. I have a function that creates the column, but i call this function before the creating column function. No wonder it did not came out. Thx alot! :) But how do i extract the "--" and solve the debug assertion error? the error occurs when the function exits the while loop.
if sBuf.Find("\t") fail ,it returns -1.
then sBuf.Mid(0,endAt)may cause a assertion error
 
Share this answer
 
Comments
skfoo1 16-Feb-12 19:37pm    
Actually, this is the part that is giving me the problem.


Token = sBuf.Tokenize(Seperator, Position);
while(!Token.IsEmpty())
{
// Get next token.
Token = sBuf.Tokenize(Seperator, Position);
}

Everytime after i exit the loop, it will give me the assertion error. It seems that "Position" will return a -1 whenever it finished its job.
I've solved this. I initialized the "Position" at the wrong location. That's why it keeps giving me the debug assert error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900