-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex1_21.c
42 lines (38 loc) · 921 Bytes
/
ex1_21.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#define TAB_WIDTH 8
int main()
{
int c, nos, ctr, i, not, lt, rs;
nos = ctr = not = 0;
while ((c = getchar()) != EOF) {
if (c == '\n') {
nos = ctr = 0;
putchar('\n');
}
else if ((nos == 0) && (c != ' ')) {
putchar(c);
++ctr;
}
else if (c == ' ') {
++nos;
++ctr;
}
else if ((c != ' ') && (nos > 0)) {
++ctr;
for (i = (ctr - nos); i < ctr; i++) {
if (i % TAB_WIDTH == 0) {
++not;
lt = i;
}
}
rs = ctr - lt - 1;
for (i = 0; i < not; i++)
putchar('\t');
for (i = 0; i < rs; i++)
putchar(' ');
putchar(c);
nos = not = 0;
}
}
return 0;
}