Using scanf to accept user input

前端 未结 5 657
轻奢々
轻奢々 2020-12-06 13:52

gcc 4.4.2

I was reading an article about scanf. I personally have never checked the return code of a scanf.

#include 

int main(void)
         


        
5条回答
  •  悲哀的现实
    2020-12-06 14:29

    I rarely use scanf. Most of the times, I use fgets() to read data as a string. Then, depending upon the need, I may use sscanf(), or other functions such as strto* family of functions, str*chr(), etc., to get data from the string.

    If I use scanf() or fgets() + sscanf(), I always check the return values of the functions to make sure they did what I wanted them to do. I also don't use strtok() to tokenize strings, because I think the interface of strtok() is broken.

提交回复
热议问题