summaryrefslogtreecommitdiff
path: root/ex1-8.c
blob: 3ba90d01bc2d129ee831d689279d6f2bf6be283d (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
#include <stdio.h>
#include <stdint.h>

struct res {
  uint64_t nl;
  uint64_t tb;
  uint64_t bl;
};

struct res nr(void) {
  struct res r = {
    .nl = 0,
    .tb = 0,
    .bl = 0.
  };
  return r;
}

static struct res _loop(struct res res) {
  int c = getchar();
  if (c == EOF) {
    return res;
  }
  if (c == ' ') {
     res = (struct res){
      .bl = res.bl+1,
      .nl = res.nl,
      .tb = res.tb,
    };
  } else if (c == '\n') {
    res.nl++;
  } else if (c == '\t') {
    res.tb++;
  }
  //__attribute__((musttail))
  return _loop(res);
}

int main(void) {
  struct res r = _loop(nr());
  printf("nl=%ld tb=%ld bl=%ld\n", r.nl, r.tb, r.bl);
  return 0;
}