|
From: <cg...@wo...> - 2002-12-25 18:49:04
|
Happy new year tewnty three (hurra for the Empire!)
I need make an operation over a huge amount of files, basically I
fstream.getline(buffer, 255); and then I do whatever. The problem is in
all the files one line is treated badly:
original:
3.429 145.1683002 5.4 0.908401 43.66
3.629 174.13 5.28 0.9093 42.86
3.859 175.61 5.14 0.909673 41.9
4.172 177.08 5.01 0.909293 40.8
4.649 178.56 4.91 0.908071 39.57
result: (I simply I original.getline(buffer, 255); result << buffer << endl;
3.429 145.1683002 5.4 0.908401 43.66
3.629 146.6423431 5.28 0.9093 42.86
671 -26.5866636 40.8 //WHY THIS HAPPENS??????????????????!!!!!!
I'M ABOUT TO KILL MY COMPUTER!!!!!
4.649 151.707065 4.91 0.908071 39.57
These are a couple of lines from original which includes the conflicting
line:, the previous one and a couple of the previous and the next. I
don't see any conflicting value. I tried to onherit from fstream and
write my own getline, so it will stop only with '\n' or end of buffer
size, but I get the same error.
number of character | character
------------------------------------
54 6
10
51 3
46 .
56 8
53 5
57 9
9
49 1
55 7
53 5
46 .
54 6
49 1
9
53 5
46 .
49 1
52 4
9
48 0
46 .
57 9
48 0
57 9
54 6
55 7
51 3
9
52 4
49 1
46 .
57 9
10
52 4
46 .
I've made a count and it seems like getline doesn't recognize the
newlines, and is filling the buffer till the 255 characters I specify as
length limit, then it jumps about the number of characters per line to
the next line, althought all the operations which are done in a
line-per-line basis are done correctly for each line. I want substract a
value for the second one each line, and all lines have the second value
they need. I've tried increasing the size of the buffer and value passed
to getline as delimiter, I doubled the size and then it makes the same
error in the next line than before, then I double it again, but then
there is no difference, the error doesn't run to the next line.
I tried to make it a UNIX kind of file (through an editor program with
this ability) but the result is still the same. In getline I checked as
delimiter for \n, \r, 10, 13 and 12, and nothing worked.
Here is the piece of code where the fail happens, when passing from the
input file to the temporary one:
while(inFile.eof() == false){
inFile.getline(buffer, 5096);
first = buffer[0];
if (first == '/') //Some lines are commented with //, I want quit them.
point = &buffer[2]; //I know if ther first is / the second is the same.
else
point = buffer;
if (tempFile.is_open()) //Compiled with and without this line.
tempFile << point << endl; .
cout << point << endl;
}
But if in cout the lines are right, then getline is working fine, the
error is in tempFile << point << endl...
I'll have to recode with plain C file functions (I've done it changing
fstream.getline with fgets and fstream << with fprintf, now it works
with other odd errors which at least don't invalidate the files, like
printing lines more than once).
However remains the question, why can it happen?
|