title: What does c!='\n' do in a for statement?
body: <p>I am a beginner and was learning to code using k&amp;r's c programming book. Now there is this example of "a program to input set of text lines and print the longest"</p>
  
  <p>I am giving you the whole code:</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
      #define MAXLINE 1000
  
      int getline(char line[], int maxline);
      void copy(char to[], char from[]);
  
      int main()
      {
      int len;
      int max;
      char line[MAXLINE];
      char longest[MAXLINE];
      max=0;
  
      while((len=getline(line,MAXLINE))&gt;0)
      if(len&gt;max)
      {
      max=len;
      copy(longest,line);
      }
      if(max&gt;0)
      printf("%s",longest);
      return 0;
      }
  
      int getline(char s[], int lim)
      {
      int c,i;
      for(i=0;i&lt;lim-1&amp;&amp;(c=getchar())!=EOF&amp;&amp;c!='\n';i++)
      s[i]=c;
      if(c=='\n')
      {
      s[i]='\n';
      i++;
      }
      s[i]='\0';
      return i;
      }
  
      void copy(char to[], char from[])
      {
      int i;
      i=0;
      while((to[i]=from[i])!='\0')
      i++;
      }
  </code></pre>
  
  <p>Now tell me, in getline function, in the statement:</p>
  
  <pre><code>    for(i=0;i&lt;lim-1&amp;&amp;(c=getchar())!=EOF&amp;&amp;c!='\n';i++)
  </code></pre>
  
  <p>why do we use " c!='\n' "</p>
  
  <p>and what is the meaning of code after this <code>for</code> statement i.e. </p>
  
  <pre><code>     s[i]=c;
       if(c=='\n)
       {
       s[i]=c;
       i++;
       }
       s[i]='\0'
  </code></pre>
  
  <p>why have we used s[i]='\0' in this?</p>
  
  <p>and <code>i++;</code> statement in <code>if(c=='\n')</code> condition?</p>