Is scanf(“%d%d”, &x, &x) well defined?

前端 未结 3 2132
无人共我
无人共我 2020-12-01 23:29

Is the following code well defined?

#include 

int ScanFirstOrSecond(const char *s, int *dest) {
    return sscanf(s, \"%d%d\", dest, dest);
}         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-02 00:16

    Yes, well defined. It means "read the first token into *dest, then read the second token into *dest again". It's weird but legal. Yes, because sscanf() executes directives in the format string in strict order.

提交回复
热议问题