While scanf!=EOF or scanf==1?

前端 未结 3 472
故里飘歌
故里飘歌 2021-01-02 06:54

Ceteris paribus (well formed data, good buffering practices and what not), is there a reason why I prefer to loop while the return of scanf is 1, rathe

3条回答
  •  迷失自我
    2021-01-02 07:20

    Depends what you want to do with malformed input - if your scan pattern isn't matched, you can get 0 returned. So if you handle that case outside the loop (for example if you treat it the same as an input error), then compare with 1 (or however many items there are in your scanf call).

提交回复
热议问题