B
Barry Schwarz
Ben said:I think that there must be something else going on. Can you post
a complete program that exhibits this behavior?
It's straight out of K&R...a simple "getline" function..
/*****/
int getline( char s[], int j){
int c,i;
i=0;
while ( --j > 0 && (c=getchar()) != EOF && c != '\n' ) /* test to
make sure line submitted is not empty */
s[i++]=c;
if ( c == '\n') /**** changing this to c=n, caused the behavior
mentioned above ****/
You forgot to quote the behavior in question but I believe you are
laboring under a misconception.
If you change the == to =, you think the while loop executes only
once. Why do you think that? Did you run the code in single step
mode under a debugger?
And please get in the habit of indenting your code consistently. It
will save you a world of headaches later on.
s='\0';
return i;
}
Remove del for email