-
Notifications
You must be signed in to change notification settings - Fork 3
/
5-12-detab.c
43 lines (33 loc) · 987 Bytes
/
5-12-detab.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
#include <stdlib.h>
#include <stdio.h>
#define DEFAULT_TABSTOP 4
int main (int argc, char **argv) {
int tabstop = DEFAULT_TABSTOP;
int start = 0;
for (int arg_index = 1; arg_index < argc; arg_index++) {
int temp = atoi(argv[arg_index]);
if (temp > 0)
tabstop = temp;
else if (temp < 0)
start = -temp;
}
int character_index = 1;
int charsBehindTabStop = 0;
char character = getchar();
while (character != '\n') {
if (character == '\t' && character_index >= start)
while (charsBehindTabStop < tabstop) {
printf("*");
charsBehindTabStop++;
}
else {
printf("%c", character);
charsBehindTabStop++;
}
if (charsBehindTabStop == tabstop)
charsBehindTabStop = 0;
character = getchar();
character_index++;
}
return 0;
}