Hansee
V2EX  ›  问与答

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

  •  
  •   Hansee · Sep 1, 2013 · 4223 views
    This topic created in 4838 days ago, the information mentioned may be changed or developed.
    7 replies  •  1970-01-01 08:00:00 +08:00
    windywinter
    windywinter
    Sep 1, 2013
    1
    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
    Hansee
    OP
    Sep 1, 2013
    2
    @windywinter 还是不太明白。其实是希望检验x,y的输入只为数字,且y不为0的判断。在sf上提问后,有人给出了这样的条件。现在输入非数字可以成功判断到,但是y为0还是无法判断。
    nybux
    nybux
    Sep 1, 2013
    3
    判断是不是读取到了2个变量,!=2没读去到,估计在if里面要有额外的错误处理
    Hansee
    Hansee
    OP
    Sep 1, 2013
    4
    @nybux 并且这两个变量会需要符合x和y声明时的类型么?因为现在输入字幕就会进入这个if语句,数字的话就会跳过。
    rteta
    rteta
    Sep 1, 2013
    5
    新手认为是,成功读入两个符合指定数据类型的数 则执行if后面的语句 C语言从来就没学会过,坐等高手指点
    Hansee
    Hansee
    OP
    Sep 1, 2013
    6
    @rteta 我现在也是这么理解的
    wang2191195
    wang2191195
    Sep 1, 2013
    7
    if (scanf("%li %li", &x, &y) != 2 && y != 0 )
    嘿嘿
    @Hansee
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4171 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 09:13 · PVG 17:13 · LAX 01:13 · JFK 04:13
    ♥ Do have faith in what you're doing.