From b514be2b8b81162921ad166afc59aeba15c3ffe2 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Tue, 18 Jan 2022 19:46:48 +0800 Subject: 5.11 --- 5/11.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 5/11.c (limited to '5') 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 +#include + +#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 -- cgit v1.2.3