Why?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,529
Latest member
JaclynShum

Latest Threads

Top