M
mdh
May I ask the following?
while ( --j > 0 && (c=getchar()) != EOF && c != '\n' )
s[i++]=c;
if ( c == '\n')
etc.
<<<
When I initially incorrectly wrote this code, I had written
"if ( c = '\n')" instead of if "( c == '\n')", apparently a common
"newby" error. I understand the difference, but what I do not
understand is this.
The code runs correctly when "....(c=='\n') is written ie the while
loop performs correctly. However, if the "c='\n' snippet is used, the
while loop only runs once. Why does the while loop not complete with
both correct and incorrect code? I would have thought the expression
"while...etc" is complete in of itlself, either way.
I hope this question makes sense. It may well be that the rest of the
code plays a role.
Thanks in advance.
while ( --j > 0 && (c=getchar()) != EOF && c != '\n' )
s[i++]=c;
if ( c == '\n')
etc.
<<<
When I initially incorrectly wrote this code, I had written
"if ( c = '\n')" instead of if "( c == '\n')", apparently a common
"newby" error. I understand the difference, but what I do not
understand is this.
The code runs correctly when "....(c=='\n') is written ie the while
loop performs correctly. However, if the "c='\n' snippet is used, the
while loop only runs once. Why does the while loop not complete with
both correct and incorrect code? I would have thought the expression
"while...etc" is complete in of itlself, either way.
I hope this question makes sense. It may well be that the rest of the
code plays a role.
Thanks in advance.