Error in reading file
-
Hi, Im reading data from file like this.. char tTagName[16] = {0} memset(tTagName,0,16); PFile.Read(tTagName,16);//tTagName is PRO01_BLC101 PFile.Read(tDesc,24);//tDesc is Liquid Level and the file looks like this... // PRO01_BLC101 Liquid Level % 2 // So it read the file fine and got correct output. But if the TagName is about 8 or 6 character it read the file wrongly..The file shows like this.. // DFC101 DEPROP FEED M3/HR 1 // I think it continously read 16 characters,so the tagname shows like "DFC101 DEPROP F " and tDesc is only "EED".. How can i avoid this..B'coz i have to work with different tagname length..It may be 4 or 8 or 16 or 20.. What can i do for this?
Anu
-
Hi, Im reading data from file like this.. char tTagName[16] = {0} memset(tTagName,0,16); PFile.Read(tTagName,16);//tTagName is PRO01_BLC101 PFile.Read(tDesc,24);//tDesc is Liquid Level and the file looks like this... // PRO01_BLC101 Liquid Level % 2 // So it read the file fine and got correct output. But if the TagName is about 8 or 6 character it read the file wrongly..The file shows like this.. // DFC101 DEPROP FEED M3/HR 1 // I think it continously read 16 characters,so the tagname shows like "DFC101 DEPROP F " and tDesc is only "EED".. How can i avoid this..B'coz i have to work with different tagname length..It may be 4 or 8 or 16 or 20.. What can i do for this?
Anu
It behaves correctly but your approach is wrong.. if you want to read different tag lenghts you can do it in two ways... 1) read byte by byte untill you fully read the tag name.... 2)just read first 16 bytes as you did and find out the excat length of tagname from the "tTagName" and then move the file pointer to the length+1 position (in your case DFC101 has length 6, so move the file pointer to position 7 from the begining of file) Hope this'll help
Do your Duty and Don't expect the Result
-
Hi, Im reading data from file like this.. char tTagName[16] = {0} memset(tTagName,0,16); PFile.Read(tTagName,16);//tTagName is PRO01_BLC101 PFile.Read(tDesc,24);//tDesc is Liquid Level and the file looks like this... // PRO01_BLC101 Liquid Level % 2 // So it read the file fine and got correct output. But if the TagName is about 8 or 6 character it read the file wrongly..The file shows like this.. // DFC101 DEPROP FEED M3/HR 1 // I think it continously read 16 characters,so the tagname shows like "DFC101 DEPROP F " and tDesc is only "EED".. How can i avoid this..B'coz i have to work with different tagname length..It may be 4 or 8 or 16 or 20.. What can i do for this?
Anu
Anu_Bala wrote:
I think it continously read 16 characters
Of course it is: you asked to read 16 characters, so it is logical that the function will read 16 characters. I suggest that you store the complete line in a big buffer and 'parse' it after that. Copy char by char in the tTagName until you reach a blank space. Then start copying in the tDesc string. That's quite easy to do.
Cédric Moonen Software developer
Charting control -
Hi, Im reading data from file like this.. char tTagName[16] = {0} memset(tTagName,0,16); PFile.Read(tTagName,16);//tTagName is PRO01_BLC101 PFile.Read(tDesc,24);//tDesc is Liquid Level and the file looks like this... // PRO01_BLC101 Liquid Level % 2 // So it read the file fine and got correct output. But if the TagName is about 8 or 6 character it read the file wrongly..The file shows like this.. // DFC101 DEPROP FEED M3/HR 1 // I think it continously read 16 characters,so the tagname shows like "DFC101 DEPROP F " and tDesc is only "EED".. How can i avoid this..B'coz i have to work with different tagname length..It may be 4 or 8 or 16 or 20.. What can i do for this?
Anu
-
It behaves correctly but your approach is wrong.. if you want to read different tag lenghts you can do it in two ways... 1) read byte by byte untill you fully read the tag name.... 2)just read first 16 bytes as you did and find out the excat length of tagname from the "tTagName" and then move the file pointer to the length+1 position (in your case DFC101 has length 6, so move the file pointer to position 7 from the begining of file) Hope this'll help
Do your Duty and Don't expect the Result
-
Anu_Bala wrote:
I think it continously read 16 characters
Of course it is: you asked to read 16 characters, so it is logical that the function will read 16 characters. I suggest that you store the complete line in a big buffer and 'parse' it after that. Copy char by char in the tTagName until you reach a blank space. Then start copying in the tDesc string. That's quite easy to do.
Cédric Moonen Software developer
Charting control -
How can i do like this? I dont know pls give me any sample..? For also copy char by char..
Anu
Hope you are using CFile.. if so use Seek method like, After find the length of tagname anf before reading the next time write this code, pFile.Seek(length+1, CFile::begin); char by char reading, is reading a single char use 1 as count in Read method pFile.Read(buff, 1); -- modified at 8:26 Wednesday 9th August, 2006
Do your Duty and Don't expect the Result
-
Hi, Im reading data from file like this.. char tTagName[16] = {0} memset(tTagName,0,16); PFile.Read(tTagName,16);//tTagName is PRO01_BLC101 PFile.Read(tDesc,24);//tDesc is Liquid Level and the file looks like this... // PRO01_BLC101 Liquid Level % 2 // So it read the file fine and got correct output. But if the TagName is about 8 or 6 character it read the file wrongly..The file shows like this.. // DFC101 DEPROP FEED M3/HR 1 // I think it continously read 16 characters,so the tagname shows like "DFC101 DEPROP F " and tDesc is only "EED".. How can i avoid this..B'coz i have to work with different tagname length..It may be 4 or 8 or 16 or 20.. What can i do for this?
Anu
Take a look at scanf.
Cheers Steen. "Are you gonna check your makeup when you're done whining?" John Simmons, 05/31/2006
-
Hi, Im reading data from file like this.. char tTagName[16] = {0} memset(tTagName,0,16); PFile.Read(tTagName,16);//tTagName is PRO01_BLC101 PFile.Read(tDesc,24);//tDesc is Liquid Level and the file looks like this... // PRO01_BLC101 Liquid Level % 2 // So it read the file fine and got correct output. But if the TagName is about 8 or 6 character it read the file wrongly..The file shows like this.. // DFC101 DEPROP FEED M3/HR 1 // I think it continously read 16 characters,so the tagname shows like "DFC101 DEPROP F " and tDesc is only "EED".. How can i avoid this..B'coz i have to work with different tagname length..It may be 4 or 8 or 16 or 20.. What can i do for this?
Anu
Anu_Bala wrote:
char tTagName[16] = {0} memset(tTagName,0,16);
What are you trying to accomplish here? :confused: One or the other is sufficient, but not both. Use this as a starting point:
void main( void )
{
ifstream ifs("c:\\a.txt");
string sLine,
sTagName,
sDesc;while (getline(ifs, sLine)) { istringstream iss(sLine); iss >> sTagName >> sDesc; // assumes a space delimeter cout << sTagName << "|" << sDesc << "|" << endl; }
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb