Skip to content

Commit a8433b9

Browse files
committed
simplify logic
1 parent f2f9b59 commit a8433b9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

chapter_1/exercise_1_12/copy_io_nl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ int main()
66
char last_char = -1;
77

88
while ((c = getchar()) != EOF) {
9-
if(c==' ' || c=='\t' || c=='\n'){
10-
if(last_char!=' ' && last_char!='\t' && last_char!='\n'){
9+
if((c==' ' || c=='\t' || c=='\n')) {
10+
if(c != last_char) {
1111
putchar('\n');
1212
}
1313
}
1414
else {
1515
putchar(c);
1616
}
17+
1718
last_char=c;
1819
}
1920

2021
return 0;
2122
}
23+

0 commit comments

Comments
 (0)