-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentab.c
45 lines (39 loc) · 880 Bytes
/
entab.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
43
44
45
#include <stdio.h>
void entab(const char *input) {
int position = 0;
int space_count = 0;
const int TABSTOB = 1;
while (*input) {
char c = *input++;
if (c == ' ') {
space_count++;
if ((position + 1) % TABSTOB == 0) {
putchar('\t');
space_count = 0;
}
position++;
} else {
while (space_count > 0) {
putchar(' ');
space_count--;
}
putchar(c);
if (c == '\n') {
position = 0;
} else {
position++;
}
}
}
while (space_count > 0) {
putchar(' ');
space_count--;
}
}
int main() {
char line[1024];
while (fgets(line, sizeof(line), stdin)) {
entab(line);
}
return 0;
}