summaryrefslogtreecommitdiffstats
path: root/5/11.c
blob: e40a0515e81823ce7f1b4ad23de004d933ae7dc9 (plain)
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
44
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);
}