Re: Reading data from a tab delimited text
I've tried to apply your change Gunaamirthavelu,but unfortunately it doesn't work...
It seems that when i do:
Code:
while(in>>data>>ora>>temperatura>>umidita>>pressione>>peso>>velvento>>pioggia>>radsol)
,where data and ora are char[8] and the others double,the first character read,i.e. the one stored in data[0],is an empty character..
I don't really have a clue about this,can you help me?
Re: Reading data from a tab delimited text
The simplest way for us to help you would be by seing the program and the test data. Upload the text file as well as the project (actually a trimmed down version that replicates the problem would be better).
1 Attachment(s)
Re: Reading data from a tab delimited text
Here's a small test application with one of my archives.
Re: Reading data from a tab delimited text
when posting code you should delete all the obj, ncb, pch files from the archive.
Re: Reading data from a tab delimited text
Re: Reading data from a tab delimited text
Yuor problem is cause by a write outside bounds. You define date and ora as
char date[18],ora[18]; and you read from file values such as 22/03/06 and 16:44:26.
The problem is that in >> data and in >> ora will write 9 chars in your variables not 8. The 9th ( warrior) is the terminating 0.
Note: due to how your variables are layed out in memory, the 9th char in ora happens to be the 1st in data, thus in >> ora, by writting 9 chars, will "empty" data ( its first char is 0).
You could try to solve this issue by increasing the size of your char arrays but this kind of problem can comeback at any change of the file layout. The safest option is to use std::string instead.
Code:
std::string date, ora;
double temperatura,umidita,pressione,peso,velvento,pioggia,radsol;
CString strHour,strDate;
char strFilter[]={"TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||"};
CFileDialog fdlgChoose(TRUE,".txt",NULL,OFN_READONLY,strFilter,this);
if(fdlgChoose.DoModal()==IDOK)
{
std::ifstream in(fdlgChoose.GetPathName());
std::string line;
std::getline(in,line);
std::getline(in,line);
std::getline(in,line);
std::getline(in,line);
std::getline(in,line);
std::getline(in,line);
std::getline(in,line);
while(in>>date>>ora>>temperatura>>umidita>>pressione
>>peso>>velvento>>pioggia>>radsol)
{
//strHour=ora;
//strDate=date;
}
}
Re: Reading data from a tab delimited text