getc Vs getchar Vs Scanf for reading a character from stdin

后端 未结 2 1812
温柔的废话
温柔的废话 2020-12-02 23:13

Of the below three functions:

getc getchar & scanf

which is the best one for reading a character from stdin and why?

Are there any known disadvan

2条回答
  •  感情败类
    2020-12-03 00:08

    from Beej's Guide to C Programming

    All of these functions in one way or another, read a single character from the console or from a FILE. The differences are fairly minor, and here are the descriptions:

    getc() returns a character from the specified FILE. From a usage standpoint, it's equivalent to the same fgetc() call, and fgetc() is a little more common to see. Only the implementation of the two functions differs.

    fgetc() returns a character from the specified FILE. From a usage standpoint, it's equivalent to the same getc() call, except that fgetc() is a little more common to see. Only the implementation of the two functions differs.

    Yes, I cheated and used cut-n-paste to do that last paragraph.

    getchar() returns a character from stdin. In fact, it's the same as calling getc(stdin).

提交回复
热议问题