Is using a while block to do nothing a bad thing?

后端 未结 12 1010
予麋鹿
予麋鹿 2021-02-01 03:29

I\'m currently working through the excercises in \'The C Programming Language\'. Here\'s one of my solutions:

int c;

while ((c=getchar()) != EOF) {

if (c == \         


        
12条回答
  •  你的背包
    2021-02-01 04:06

    Well if you really don't like the empty braces, you could refactor that inner loop into

    while (c == ' ') {c = getchar();}
    

    This costs one extra comparison though, so a do while loop would be better.

提交回复
热议问题