Chris Theis wrote:
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:43***************@gascad.at... an********@gmail.com wrote:
char name[2];
[snip]
im using i to increment each time the loop goes round thus counting the
no. of lines. however the line ' fin>>name>>node1>>node2>>value;' keeps
setting i to 0 so it never counts it. How do i fix this, or is there
another way to do this?
What is stored in 'name'?
Note that name has only room for a size-2 string.
That is: one lettter plus the terminating '\0'
Other then that:
Your use of eof is wrong, but that does not explain the
magical change of 'i'.
IMHO that magical change of i could only be achieved by aliasing or
completely broken optimization of the compiler.
Well. My personal guess is, that his file format looks like this
AB 1 2 2.0
CD 3 4 5.0
since the first column in his file contains 2 characters and
the variable receiving that string is defined as
char name[2];
the input operation is overflowing the array. And since
i is immediatly defined before that array, the overflow
happens such that the terminating '\0' is 'resetting' i in
each input operation. For this the compiler might have
arranged things on the stack such that i has a higher
address on the CPU stack but is immediatly following
name in memory. A lot of compilers would do it that way.
But this is just my personal guess and of course is
completely implementation dependent. Nevertheless I
think it is a good theory and to verify it, the exact
file format would be needed.
--
Karl Heinz Buchegger
kb******@gascad.at