to all coders whether beginners or experiences please help me with this c code : "please give me quite an explaination so that i can understand my query properly...thank you :) " 
i am a beginner and was learning to code using k&r's c programming book. now there is this example of "a program to input set of text lines and print the longest"
i am giving you the whole code......

        #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))>0)

        if(len>max)

        {

        max=len;

        copy(longest,line);

        }

        if(max>0)

        printf("%s",longest);

        return 0;

        }

        int getline(char s[], int lim)

        {

        int c,i;

        for(i=0;i<lim-1&&(c=getchar())!=EOF&&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++;

        }

now tell me....
in getline function....
in the statement

        for(i=0;i<lim-1&&(c=getchar())!=EOF&&c!='\n';i++)

why do we use " c!='\n' "

and 
what is the meaning of code after this for statement

i.e. 

         s[i]=c;

         if(c=='\n)
         
         {

         s[i]=c;

         i++;

         }

         s[i]='\0'

why have we used s[i]='\0' in this

and i++; statement in if(c=='\n') condition
