Skip to content

Commit a53391b

Browse files
committed
fix exercise 1-12 edge cases
1 parent 1506a2a commit a53391b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

chapter_1/exercise_1_12/copy_io_nl.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
int main()
44
{
5-
char c;
6-
char last_char = -1;
5+
int c, prev;
6+
prev = EOF;
77

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

18-
last_char=c;
18+
prev = c;
1919
}
2020

2121
return 0;
2222
}
23-

0 commit comments

Comments
 (0)