line[len-1]='\0'
because getline
puts \n
in last character.
see in getline
function
if(c=='\n'){s[i]=c;++i; }
Also
p
is allocated to block of length of line
so that line could be copied to to because line
is used to store subsequent characters line, if it is not copied all line will be lost.