Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions chapter_2/exercise_2_02/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ int main(void)
{
char c = getchar();

if (i >= (MAXLINE - 1))
if (i >= (MAXLINE - 1) || c == '\n' || c == EOF)
{
loop = 0;
break;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamiNasry Can we have it without the break until we figure out what's up with that? I find it very educational to learn how to deal with the differences between different machines.

PS: I'm used to writing code in high-level programming languages, and I almost forgot about all these low-level implementation details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I removed the break until we figure out why it acts like this. Thanks for your time.

}
else if (c == '\n')
{
loop = 0;
}
else if (c == EOF)
{
loop = 0;
}

s[i++] = c;
}

Expand Down
Loading