Skip to content

Commit 3fb4576

Browse files
authored
Update loop.c to be more compact
1 parent 85067db commit 3fb4576

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

chapter_2/exercise_2_02/loop.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,11 @@ int main(void)
1919
{
2020
char c = getchar();
2121

22-
if (i >= (MAXLINE - 1))
22+
if (i >= (MAXLINE - 1) || c == '\n' || c == EOF)
2323
{
2424
loop = 0;
2525
break;
2626
}
27-
else if (c == '\n')
28-
{
29-
loop = 0;
30-
break;
31-
}
32-
else if (c == EOF)
33-
{
34-
loop = 0;
35-
break;
36-
}
37-
3827
s[i++] = c;
3928
}
4029

0 commit comments

Comments
 (0)