summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2022-01-18 19:46:48 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2022-01-18 19:46:48 +0800
commitb514be2b8b81162921ad166afc59aeba15c3ffe2 (patch)
treecbb75fb9016e5d6e9f40852b83723630c66fb39b
parent3f4d2761c1eec8ae51fc42510a014d3f7f26d632 (diff)
downloadk&r-exercises-b514be2b8b81162921ad166afc59aeba15c3ffe2.tar.gz
5.11
-rw-r--r--5/11.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/5/11.c b/5/11.c
new file mode 100644
index 0000000..e40a051
--- /dev/null
+++ b/5/11.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TABSIZE 8
+#define MAXLEN 1000
+
+void entab(char *s, char *t, int *tablist, int tablistc);
+
+int main(int argc, char *argv[]) {
+ int colc, *tablist, *tablistp;
+ char *s, *col, *colp, *colstr;
+
+ s = malloc(sizeof(char) * MAXLEN);
+ col = malloc(sizeof(char) * MAXLEN);
+ colp = col;
+
+ if (argc < 2) {
+ tablist = malloc(sizeof(int));
+ tablist[0] = 8;
+ } else {
+ tablist = malloc(sizeof(int) * 100);
+ tablistp = tablist;
+ for (colstr = argv[1]; *colstr != 0; colstr++) {
+ if (*colstr == '"')
+ continue;
+ if (*colstr == ',' || *colstr == ' ') {
+ // todo: realloc based on colc
+ colc++;
+ *colp++ = 0;
+ colp = col;
+ *tablistp = atoi(col);
+ tablistp++;
+ } else {
+ *colp++ = *colstr;
+ }
+ }
+ }
+
+ printf("Enter text to entab\n");
+ fgets(s, MAXLEN, stdin);
+
+ free(s);
+ free(col);
+ free(tablist);
+} \ No newline at end of file