Reading text file
I try to read a line of text in a file that looks like this: 10N11M12R
where N, M and R are numbers from 1 to 2000.
For 3-digit numbers, I extracted N, M and R in this way:
How can parse this line and determine the number of digits that contains N, M and R?
int count = 0;
CStdioFile file(_T("temp.txt"), CFile::modeRead);
CString str,mainstr = _T("");
mainstr += str;
mainstr += _T("\n");
textBox2 ->SetWindowTextA(mainstr.Mid(3,3)); // N
textBox3 ->SetWindowTextA(mainstr.Mid(10,3)); // M
textBox4 ->SetWindowTextA(mainstr.Mid(17,3)); // R
catch(CException* e)//Catch by pointer as exceptions in MFC are crap
MessageBox(_T("Error - unable to open file"));
e->Delete();//Lame...very lame...but needed
Id try something like this
This is not tested and propably wrong too but I hope you get the idea.
nr_N = mainstr.Find('N',0);
nr_M = mainstr.Find('M', nr_N+1) - nr_N - 1;
nr_R = mainstr.GetLength() - ( nr_N + nr_M + 2);
should get you started on finding integers within a string.
Thanks, I try with your Feedback
Thanks all, is now working.
The release work fine on Windows 7 but not on XP(SP3). I have installed on XP Framework 4 and installed the application.
Wen i try to write something througth the serialport, I get write failed. I cann't debug on Xp because VC 2010 ist not installed.
The application is a MFC in a static Library and I think isn't a dll problem. What can the problem be?