本文介绍了是'sscanf`保证不会改变参数,它并没有找到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里,我不知道我是否会得到的sscanf 足够输入的情况下。我可以肯定地认为的sscanf 将不会与任何说法,它没有找到烂摊子?

例如,在此程序:

 的#include<&stdio.h中GT;INT主(INT ARGC,字符** argv的){
    诠释一个= 0,B = 0,C = 0;
    sscanf的(1 2,%D%D,&安培; A,和B,和C);
    的printf(%d个%D \\ n,A,B,C);
    返回0;
}

输出是:

So, it read two of the three numbers, and didn't mess with the last one. Can I safely assume that all compilers and standard libraries will also leave the last argument alone in this case, or do I need to do something like this:

int main(int argc, char** argv) {
    int a = 0, b = 0, c = 0;
    if (sscanf("1 2", "%d %d %d", &a, &b, &c) != 3) {
        c = 0;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}
解决方案

You are completely safe.

In C11, 7.21.6.7 The sscanf function

7.21.6.2 The fscanf function says,

Your case is an input failure.

这篇关于是'sscanf`保证不会改变参数,它并没有找到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 09:54