Hansee
V2EX  ›  问与答

if (scanf("%li %li", &x, &y) != 2 ) 请问这个条件应该怎么理解?

  •  
  •   Hansee · Sep 1, 2013 · 3846 views
    This topic created in 4667 days ago, the information mentioned may be changed or developed.
    7 replies    1970-01-01 08:00:00 +08:00
    windywinter
        1
    windywinter  
       Sep 1, 2013
    On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.
    Hansee
        2
    Hansee  
    OP
       Sep 1, 2013
    @windywinter 还是不太明白。其实是希望检验x,y的输入只为数字,且y不为0的判断。在sf上提问后,有人给出了这样的条件。现在输入非数字可以成功判断到,但是y为0还是无法判断。
    nybux
        3
    nybux  
       Sep 1, 2013
    判断是不是读取到了2个变量,!=2没读去到,估计在if里面要有额外的错误处理
    Hansee
        4
    Hansee  
    OP
       Sep 1, 2013
    @nybux 并且这两个变量会需要符合x和y声明时的类型么?因为现在输入字幕就会进入这个if语句,数字的话就会跳过。
    rteta
        5
    rteta  
       Sep 1, 2013
    新手认为是,成功读入两个符合指定数据类型的数 则执行if后面的语句 C语言从来就没学会过,坐等高手指点
    Hansee
        6
    Hansee  
    OP
       Sep 1, 2013
    @rteta 我现在也是这么理解的
    wang2191195
        7
    wang2191195  
       Sep 1, 2013
    if (scanf("%li %li", &x, &y) != 2 && y != 0 )
    嘿嘿
    @Hansee
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2974 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 10:49 · PVG 18:49 · LAX 03:49 · JFK 06:49
    ♥ Do have faith in what you're doing.