For loop with sscanf crashes after first iteration

For some reason, this for loop causes the program to crash RIGHT after the first iteration. No error message, no segfault, just stops working.



myTest is a separate class, v is a vector, both of which have been tested to work fine otherwise. For loops everywhere else in the code work fine too. The if statement is just the first part of what's going to go in there. The code prints out

start
end

And then crashes. I've tested the code within and found that it works correctly, scanning the line and pushing the values into the vector. But for some reason it just completely crashes after the first iteration. I'm completely baffled, any ideas would be greatly appreciated.

UPDATE: getting rid of the sscanf line makes it work, so that's clearly the problem, but I can't for the life of me figure out why. Does sscanf have a habit of screwing anything up?
Last edited on
I may have figured out the problem. It seems having x y and z inside the for loop messes it up. However, it would still be useful to know why. Anyone know?
Several possible problems.
1. There is no check that the getline succeeded.
2. There is no check that the sscanf succeeded.

A sample of the file contents would be useful.
The file has many lines of data that follow specific, easy-to-extract formats. For example:

z 0.332 0.39 0.223
f 0.66 1.76 2.88

Some of them have different formats, but that if statement focuses on the one that follows that format.
Topic archived. No new replies allowed.