for(i=0;i<lim-1&&(c=getchar())!=EOF&&c!='\n';i++)
why do we usec!='\n'
We use c!='\n' to stop scanning input characters when user enters a \n (newline) character or in other words,when user hits the enter key.
why have we used
s[i]='\0'in andi++;statement inif(c=='\n')condition
-
i++is used to increase the index value of the array/string for one last time to accomadate the terminating'\0'null character. -
s[i]='\0'is used to terminate\end the string with a null character. This is essential for marking the end of the string and printing a string within bounds (upto'\0'character)
11
solved What does c!=’\n’ do in a for statement?