Skip to content

Commit b4ba698

Browse files
authored
Merge pull request #56 from danielcft/patch-1
fix 1-12
2 parents 7f68da5 + a8433b9 commit b4ba698

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

chapter_1/exercise_1_12/copy_io_nl.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
#include <stdio.h>
22

3-
int main(void)
3+
int main()
44
{
55
char c;
6+
char last_char = -1;
67

7-
while ((c = getchar()) != EOF)
8-
{
9-
if (c == ' ' || c == '\t' || c == '\n')
10-
{
11-
putchar('\n');
8+
while ((c = getchar()) != EOF) {
9+
if((c==' ' || c=='\t' || c=='\n')) {
10+
if(c != last_char) {
11+
putchar('\n');
12+
}
1213
}
13-
else
14-
{
14+
else {
1515
putchar(c);
1616
}
17+
18+
last_char=c;
1719
}
1820

1921
return 0;
2022
}
23+

0 commit comments

Comments
 (0)