Instead of using sscanf()
and a format specifier use std::istringstream
with operator>>()
:
if (fgets( buffer, BUFSIZE, in_file ))
{
std::istringstream in(buffer);
if (!(in >> num_rows))
{
// Handle failure.
}
}
Replacing the (not shown) FILE*
and with a std::ifstream
would enable removal of the std::istringstream
and just read directly from the std::ifstream
instead.