diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2022-01-28 19:07:21 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2022-01-28 19:07:21 +0800 |
| commit | eb5053b050ec1d03d1f5307f8b45abdfc614b9fa (patch) | |
| tree | eda0c607ce3ae9d07905b2360a8a95566e95207a | |
| parent | a1ccfd9268152f086d83ac337a8def3984984f3e (diff) | |
| download | k&r-exercises-eb5053b050ec1d03d1f5307f8b45abdfc614b9fa.tar.gz | |
5.11
| -rw-r--r-- | 5/11.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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, l, m; if (tablistc < 2) { for (i = 0, j = 0; s[i] != 0 && j < MAXTEXT; i++) { @@ -109,7 +109,27 @@ void entab(char *s, char *t, int *tablist, int tablistc) { t[j] = 0; } else { - // todo + for (i = 0, j = 0, k = 0; i < tablistc && s[j] != 0; j++) { + if (s[j] != ' ') { + t[k++] = s[j]; + if (s[j] == '\n') + l = 0; + else + l++; + } else { + for (m = j; m <= tablist[i] && s[m] == ' '; m++) + ; + if (m == tablist[i]) { + t[k++] = '\t'; + l = m + 1; + } else { + t[k++] = s[j]; + l++; + } + } + } + + t[k] = 0; } } |
