0

I have this:

#include<stdio.h>
#include<string.h>
int main(void)
{
    int ret;
    int major =0, minor= 0, build =0, revision =0;
    char entry[16];
    strcpy(entry,"1.2");
    ret = sscanf(entry,"%d.%d.%d.%d", &major, &minor, &build, &revision);
    printf("sscanf(""%s"") returned %d\r\n", entry, ret);
    printf("major=%d, minor=%d, build=%d, revision=%d\r\n",
        major, minor, build, revision);
    return ret;
}

After sscanf is called, ret is -1, but first two entries are filled (major is 1, minor is 2). I was expecting ret to be 2. I don't know what is wrong.

Evil Dog Pie
  • 2,300
  • 2
  • 23
  • 46
Jiminion
  • 5,080
  • 1
  • 31
  • 54

1 Answers1

1

OK, I think I figured out the problem. The behavior is ok (it works) under VS 2013. But the CVI Version (National Instruments) simply doesn't play by the rules.

sscanf() under CVI returns a -1 when only a partial match occurs, but it makes the partial matches. It also does nothing with errno, which apparently, scanf functions are allowed to ignore.

So 'answer' is a non-compatible version of sscanf under CVI.

If anyone wants to post an answer, I will accept and credit it.

Jiminion
  • 5,080
  • 1
  • 31
  • 54
  • You should update your question to include a [MCVE](http://stackoverflow.com/help/mcve) . Otherwise the possibility exists that you have got a bug somewhere in the code that you were running in CVI. – M.M May 18 '15 at 13:40
  • This is a MCVE with CVI. – Jiminion May 18 '15 at 13:41