K&R Exercise 1.16 - Limitation on line length

前端 未结 5 598
时光说笑
时光说笑 2020-12-31 04:17

I\'m learning C from K&R\'s \"The C Programming Language\" book. I\'m doing the exercises specified in the book. I\'m on exercise number 1.16, but I don\'t understand it

5条回答
  •  旧巷少年郎
    2020-12-31 04:55

    
    
        #include
    
        main()
        {
           long tlength = 0;
           short input, llength = 1;
           while (llength > 0)  {
              llength = 0;
              while ((input = getchar()) != EOF) {
                  ++llength;
                  if (input == '\n')
                  break;
              }
              tlength = tlength + llength;
              printf("\nLength of just above line : %5d\n\n", llength);
           }
           printf("\n\tLength of entire text : %8ld\n", tlength);
           return 0;
        }
    
    

    According to me, This question only wants the length of each arbitrarily line + At last the length of entire text.

    Try to run this code and tell me is it correct according to question because i too confuse in this problem.

提交回复
热议问题