-1

#include <stdio.h>

int main()
{
    char c;
    char d[10000];
    int i = 0, nl = 0,ll = 0,k = 0;
    int maxi = 0;
    while((c=getchar()) != EOF){
        d[i]=c;
        if(c == '\n'){
            ++nl;
            ll = i - k; //line length
            k = i;
            if(maxi<=ll){
                maxi=ll;
                printf("%d",maxi); //**(1)**
            }
        }
        ++i;
    }
    // printf("%d",maxi); **(2)**
}

why is the variable not assigned the value at position (2) of the program? it only prints in position (1)?

1 Answers1

1

You should get into the habit of putting a newline (\n) at the end of your printf formats. That will usually make the data easier to read, and it will mostly save you from having to think about stdout buffering. (q.v.)

Also, I've heard that some IDEs swallow the last line of output if it's not terminated with a newline.

Sometimes, of course, you will want to use more than one printf call to print a single line; in that case, you only put the \n for the last printf in the line. But the normal case is that every format string ends with \n.

rici
  • 234,347
  • 28
  • 237
  • 341