Where does `getchar()` store the user input?

后端 未结 7 2142
情深已故
情深已故 2020-12-16 04:25

I\'ve started reading \"The C Programming Language\" (K&R) and I have a doubt about the getchar() function.

For example this code:

#         


        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 05:05

    the code is functionally equivalent to

    main(){
      int c;
      c = getchar();
      while(c != EOF) {
        putchar(c);
        c = getchar();
      }
    }
    

    you might find this version easier to understand. the only reason to put the assignment in the conditional is to avoid having to type 'c=getchar()' twice.

提交回复
热议问题