Skip to content

Commit 56c7779

Browse files
authored
fix 1-12
The program does not take into account if blank, tab or newlines are repeated. Example: test.txt (notice blanks after 'This is a') ``` This is a succession of blanks. ``` `./a.out < test.txt` ``` This is a succession of blanks. ``` whereas we expect ``` This is a succession of blanks. ``` succession of blanks.
1 parent 7f68da5 commit 56c7779

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#include <stdio.h>
2-
3-
int main(void)
4-
{
5-
char c;
6-
7-
while ((c = getchar()) != EOF)
8-
{
9-
if (c == ' ' || c == '\t' || c == '\n')
10-
{
11-
putchar('\n');
12-
}
13-
else
14-
{
15-
putchar(c);
16-
}
17-
}
18-
19-
return 0;
20-
}
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
char c;
6+
char last_char = -1;
7+
while ((c = getchar()) != EOF) {
8+
if(c==' ' || c=='\t' || c=='\n'){
9+
if(last_char!=' ' && last_char!='\t' && last_char!='\n'){
10+
putchar('\n');
11+
}
12+
last_char=c;
13+
}
14+
else {
15+
putchar(c);
16+
last_char=c;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)