Why does this piece of code output the wrong length number. Say the user inputs “hello”, which is 5 characters long, this program says it is 6 character log. Please explain the logic. Also, please edit the code so that it can produce the correct output.
#include <stdio.h>
int main ()
{
int len;
char = ch;
printf(“Enter a word”);
for (len = 0; ch != ‘n’; len++)
{
ch = getchar();
}
printf(“Length = %d”, len);
return 0;
}