Click here to Skip to main content
15,914,452 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: anyone know this error ? Pin
Nitron8-Jan-03 7:09
Nitron8-Jan-03 7:09 
GeneralRe: anyone know this error ? Pin
joshfl8-Jan-03 7:39
joshfl8-Jan-03 7:39 
GeneralMRU Pin
tsb8-Jan-03 6:51
tsb8-Jan-03 6:51 
GeneralRe: MRU Pin
Gary Kirkham8-Jan-03 8:00
Gary Kirkham8-Jan-03 8:00 
Generalbackground color Pin
MemLeak8-Jan-03 6:38
MemLeak8-Jan-03 6:38 
GeneralRe: background color Pin
Mazdak8-Jan-03 6:45
Mazdak8-Jan-03 6:45 
GeneralRe: background color Pin
Mazdak8-Jan-03 6:50
Mazdak8-Jan-03 6:50 
GeneralParsing a CSV file - problem Pin
lbc8-Jan-03 6:19
lbc8-Jan-03 6:19 
Hello everybody, i am trying to parse a simple CSV file (see a little file sample below) using the functions found in the book 'PROFESSIONAL MFC with VC++6' by M. Blaszczak, Wrox. I am working with VC7.
The functions work fine but unfortunately i can get only the first, say, N-1 values parsed instead of all the N wished ones.

for example in the sample below

i get parsed only:
label0 .. label5 as labels row (missing label6)
field0,f1,f2,f3,f4,f5 as first row of values (missing field f6)
0,10,20,30,40,50 as second row of values (missing 60)
and so on...
I mean only six values (with reference to the csv file sample), not all the seven values

any help/tip will be gratly appreciated!
Thanks in advance

<br />
class CMyDoc : public CDocument<br />
{<br />
<br />
public:<br />
	int CountChars(CString& ref, TCHAR ch = ',') const;<br />
	CString GetField(CString& ref, int nIndex, TCHAR ch = ',') const;<br />
<br />
...<br />
<br />
<br />
};<br />
<br />
...<br />
<br />
int CMyDoc::CountChars(CString& ref, TCHAR ch) const<br />
{<br />
	LPCTSTR pstrBuffer = ref.LockBuffer();<br />
	int nCount = 0;<br />
<br />
	while (*pstrBuffer != _T('\0'))<br />
	{<br />
		if (*pstrBuffer == ch)<br />
			nCount++;<br />
		pstrBuffer++;<br />
	}<br />
<br />
	ref.UnlockBuffer();<br />
	return nCount;<br />
}<br />
<br />
<br />
CString CMyDoc::GetField(CString& ref, int nIndex, TCHAR ch) const<br />
<br />
<br />
{<br />
	CString strReturn;<br />
	LPCTSTR pstrStart = ref.LockBuffer();<br />
	LPCTSTR pstrBuffer = pstrStart;<br />
	int nCurrent = 0;<br />
	int nStart = 0;<br />
	int nEnd = 0;<br />
	int nOldStart = 0;<br />
<br />
	while (nCurrent <= nIndex && *pstrBuffer != _T('\0'))<br />
	{<br />
		<br />
		if (*pstrBuffer == ch)<br />
		{<br />
			nOldStart = nStart;<br />
			nStart = nEnd+1;<br />
			<br />
			nCurrent++;<br />
		}<br />
<br />
		<br />
		nEnd++;<br />
		pstrBuffer++;<br />
	}<br />
<br />
	ref.UnlockBuffer();<br />
<br />
	<br />
	if (*pstrBuffer == _T('\0'))<br />
	{<br />
		TRACE("Warning: Couldn't find it.\n");<br />
		return strReturn;<br />
	}<br />
	<br />
	return ref.Mid(nOldStart, nEnd-nOldStart-1);<br />
}<br />
<br />
<br />
<br />
...<br />
<br />
// CALLING STUFF<br />
<br />
...<br />
<br />
int nColumns = pDoc->CountChars(pDoc->m_strColumns);<br />
	TRACE("N. col= %d, header titles= %s\n", nColumns, pDoc->m_strColumns);<br />
	int nIndex;<br />
	CString strCurrent;<br />
	for (nIndex = 0; nIndex < nColumns; nIndex++)<br />
	{<br />
		... print values ...<br />
	}<br />


SAMPLE FILE.CSV

label0,label1,label2,label3,label4,label5,label6 <-- labels row
field0,f1,f2,f3,f4,f5,f6 <-- first row of values
0,10,20,30,40,50,60 <-- second row of values
...



best regards
GeneralRe: Parsing a CSV file - problem Pin
Nitron8-Jan-03 6:28
Nitron8-Jan-03 6:28 
GeneralRe: Parsing a CSV file - problem Pin
Nitron8-Jan-03 6:31
Nitron8-Jan-03 6:31 
GeneralRe: Parsing a CSV file - problem Pin
lbc8-Jan-03 6:45
lbc8-Jan-03 6:45 
GeneralDoc - View Architecture Question! Pin
Raphael Kindt8-Jan-03 6:01
Raphael Kindt8-Jan-03 6:01 
GeneralRe: Doc - View Architecture Question! Pin
Alvaro Mendez8-Jan-03 6:19
Alvaro Mendez8-Jan-03 6:19 
GeneralRe: Doc - View Architecture Question! Pin
Ranjan Banerji8-Jan-03 6:26
Ranjan Banerji8-Jan-03 6:26 
GeneralRe: Doc - View Architecture Question! Pin
KaЯl9-Jan-03 3:11
KaЯl9-Jan-03 3:11 
GeneralRe: Doc - View Architecture Question! Pin
Raphael Kindt9-Jan-03 3:21
Raphael Kindt9-Jan-03 3:21 
GeneralClass and variable renaming Pin
Alois Kraus8-Jan-03 4:30
Alois Kraus8-Jan-03 4:30 
GeneralRe: Class and variable renaming Pin
AlexO8-Jan-03 5:28
AlexO8-Jan-03 5:28 
GeneralRe: Class and variable renaming Pin
Alvaro Mendez8-Jan-03 5:43
Alvaro Mendez8-Jan-03 5:43 
GeneralDetecting double-click on popup menu Pin
mynab8-Jan-03 3:51
mynab8-Jan-03 3:51 
Generaleek! CBrush & SelectObject problem Urgent cwk Pin
smiler8-Jan-03 3:44
smiler8-Jan-03 3:44 
GeneralRe: eek! CBrush & SelectObject problem Urgent cwk Pin
56789012348-Jan-03 3:57
56789012348-Jan-03 3:57 
GeneralRe: eek! CBrush & SelectObject problem Urgent cwk Pin
smiler8-Jan-03 4:16
smiler8-Jan-03 4:16 
GeneralRe: eek! CBrush & SelectObject problem Urgent cwk Pin
jhwurmbach8-Jan-03 4:06
jhwurmbach8-Jan-03 4:06 
Generalsplitting the window Pin
atif_8-Jan-03 2:49
atif_8-Jan-03 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.