summaryrefslogtreecommitdiffstats
path: root/5/6.c
blob: d33af6ce3e6927ff282a2b675a2534b43531e4cc (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
#include <stdio.h>
#include <stdlib.h>

int mgetline(char *s, int lim) {
  int i;

  for (i = 0; i < lim - 1 && (*s++ = getchar()) != EOF && *s != '\n'; i++)
    ;

  if (*s == EOF)
    *s = 0;
  else {
    *++s = 0;
    i++;
  }

  return i;
}

int matoi(char *s) {
  int n;

  while (*s >= '0' && *s <= '9')
    n = 10 * n + (*s++ - '0');

  return n;
}