I've been given some C++ code which (among other things) reads filenames and parses them using sscanf
. However, despite using %lf
for parsing, sscanf parses the first double truncated, and then fails to parse the rest of the string.
The offending code segment is:
int row, col;
double camx, camy;
char ext[64];
char inp[64] = "out_00_00_-381.909271_1103.376221.png";
int ret = sscanf(inp, //files[i].toStdString().c_str(),
"out_%d_%d_%lf_%lf%s", &row, &col, &camy, &camx, ext);
I get the following parse:
ret=3
row=0, col=0
camy=-381
camx=[gibberish]
ext=[gibberish]
More confusingly, if I run the same code segment in repl.it, it works perfectly.
I'm compiling using CMake on Ubuntu 20.04, GCC 9.4.0 x86_64-linux-gnu. I don't fully understand CMake (since someone else gave me this repo), but I have the following CMakeLists.txt
:
include_directories("${PROJECT_SOURCE_DIR}/include" ${OpenCL_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
QT5_WRAP_CPP(lf_renderer_HEADERS_MOC LFViewWidget.h LFViewWindow.h)
add_executable(task5_lf_renderer main.cpp LFViewWindow.cpp LFViewWidget.cpp LightFieldRenderer.cpp ${lf_renderer_HEADERS_MOC})
target_compile_features(task5_lf_renderer PRIVATE cxx_range_for)
target_link_libraries(task5_lf_renderer ${OpenCL_LIBRARIES} Qt5::Widgets) #Qt5::OpenGL
where this file is LightFieldRenderer.cpp
in the add_executable()
call.
I suspect the issue is that some compile flags are being set/unset somewhere which is causing this to compile differently on my machine. Any pointers to where I should look would be much appreciated!