I have a truly ancient punch-card format and a C++ code that reads it using sscanf
as follows,
sscanf(longstr1,"%2d %5ld %1c %10s %2d %12lf %11lf %7lf %2d %7lf %2d %2d %6ld ",
&cardnumb,&satrec.satnum,&classification, intldesg, &satrec.epochyr,
&satrec.epochdays,&satrec.ndot, &satrec.nddot, &nexp, &satrec.bstar,
&ibexp, &numb, &elnum );
Here the first two characters of the string longstr1
comprise an int
read into cardnum
, the next five comprise an int
read into satrec.satnum
, and so on. (Those of a certain age will recognize this as a Hollerith format.) The placement of the characters within the string longstr1
never varies.
This works fine, but I have to make it work with both gcc
on Linux and Visual Studio C++ (2017) on Windows. VS complains that sscanf
is insecure (I suppose it is), and recommends replacing it with sscanf_s
, a Microsoft-only function. I need a substitute that makes VS happy, but compiles with gcc
on Linux, too.
Is there some secure, and perhaps easy, way to accomplish this?