Will it be too much to ask if I pray for an elucidation of the following codes from Line 7 onward? I have difficulty in comprehending how getchar() may differ from gets() or scanf() for the most parts. Why is it important to add an escape sequence, \n with it, when in my belief, the value inputting would be done in a horizontal form(as it is a 1D string)? The increment and then the immediate usage of decrement operator bewilder me too. Also, require help with the strcpy(). :| If somebody has the time, I implore guidance. Thank you!
main()
{
char st[80], ch, word[15], lngst[15];
int i, l, j;
printf("\n Enter a sentence \n ");
i = 0;
while((st[i++] = getchar()) != '\n');
i--;
st[i] = '\0';
l = strlen(st);
i = 0; j = 0;
strcpy(word," ");
strcpy(lngst," ");
while(i <= l)
{
ch = st[i];
if(ch == ' ' || ch == '\0')
{
word[j] = '\0';
if(strlen(word) > strlen(lngst))
strcpy(lngst, word);
strcpy(word," ");
j = 0;
}
else
{
word[j] = ch;
j++;
}
i++;
}
printf("\n Longest word is %s", lngst);
printf("\n Press any key to continue...");
getch();
}