summaryrefslogtreecommitdiffstats
path: root/5
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2022-01-27 21:26:22 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2022-01-27 21:26:22 +0800
commit83139dbf46bf65742ef5a2d3f022913cffd52908 (patch)
tree750d00edb198815e98cc429fdb6ba9f851b3cc63 /5
parentadb9f2b594535f9cb7b77385dc7aa3c54f1f4181 (diff)
downloadk&r-exercises-83139dbf46bf65742ef5a2d3f022913cffd52908.tar.gz
5.11
Diffstat (limited to '5')
-rw-r--r--5/11.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/5/11.c b/5/11.c
index 22560d9..72fe92f 100644
--- a/5/11.c
+++ b/5/11.c
@@ -90,7 +90,7 @@ int gettablist(char *s, int *t) {
}
void entab(char *s, char *t, int *tablist, int tablistc) {
- int i, j, k;
+ int i, j, k, col;
if (tablistc == 1) {
for (i = 0, j = 0; j < MAXTEXT && (t[j] = s[i]) != 0; i++) {
@@ -101,7 +101,19 @@ void entab(char *s, char *t, int *tablist, int tablistc) {
j++;
}
} else {
- // todo
+ col = 1;
+ for (i = 0, j = 0, k = 0; k < MAXTEXT && s[i] != 0 && j <= tablistc; i++) {
+ if (s[i] != '\t') {
+ t[k++] = s[i];
+ if (s[i] == '\n')
+ col = 1;
+ else
+ col++;
+ } else {
+ for (; col <= tablist[j++] && k < MAXTEXT; col++)
+ t[k++] = ' ';
+ }
+ }
}
t[j] = 0;